Skip to content

Commit

Permalink
user name is not getting displayed properly in poll bottom sheet (#1732)
Browse files Browse the repository at this point in the history
* Fixed participants list bug

* 🤖 Automated Format and Fix

---------

Co-authored-by: Decoder07 <[email protected]>
  • Loading branch information
Decoder07 and Decoder07 authored Mar 14, 2024
1 parent 991d7e6 commit 54ccb1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ class _PollVoteBottomSheetState extends State<PollVoteBottomSheet> {
}
}

String _getUserName(HMSPollStore hmsPollStore) {
String? userName = hmsPollStore.poll.createdBy?.name;
if (userName != null) {
if (userName.length > 15) {
return userName.substring(0, math.min(15, userName.length)) + "...";
}
return userName;
} else {
return "Participant";
}
}

@override
Widget build(BuildContext context) {
var hmsPollStore = context.watch<HMSPollStore>();
Expand Down Expand Up @@ -176,9 +188,8 @@ class _PollVoteBottomSheetState extends State<PollVoteBottomSheet> {
),
),
HMSTitleText(
text: hmsPollStore.poll.createdBy == null
? "Participant started a new ${hmsPollStore.poll.category == HMSPollCategory.poll ? "poll" : "quiz"}"
: "${hmsPollStore.poll.createdBy?.name.substring(0, math.min(15, hmsPollStore.poll.createdBy?.name.length ?? 0)) ?? ""} started a ${widget.isPoll ? "poll" : "quiz"}",
text:
"${_getUserName(hmsPollStore)} started a ${widget.isPoll ? "poll" : "quiz"}",
textColor: HMSThemeColors.onSurfaceHighEmphasis,
letterSpacing: 0.15,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:hmssdk_flutter/src/enum/hms_poll_enum.dart';
///[HMSPollAnswer] class represents answer to poll questions
class HMSPollAnswer {
final String? answerText;
final Duration duration;
final Duration? duration;
final int questionId;
final HMSPollQuestionType questionType;
final int? selectedOption;
Expand All @@ -14,7 +14,7 @@ class HMSPollAnswer {

HMSPollAnswer({
this.answerText,
required this.duration,
this.duration,
required this.questionId,
required this.questionType,
this.selectedOption,
Expand All @@ -27,7 +27,8 @@ class HMSPollAnswer {
factory HMSPollAnswer.fromMap(Map map) {
return HMSPollAnswer(
answerText: map['answer'],
duration: Duration(seconds: map['duration']),
duration:
map['duration'] != null ? Duration(seconds: map['duration']) : null,
questionId: map['question_id'],
questionType: HMSPollQuestionTypeValues.getHMSPollQuestionTypeFromString(
map['question_type']),
Expand All @@ -44,7 +45,7 @@ class HMSPollAnswer {
Map<String, dynamic> toMap() {
return {
'answer': answerText,
'duration': duration.inSeconds,
'duration': duration?.inSeconds,
'question_id': questionId,
'question_type': questionType.toString(),
'selected_option': selectedOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class HMSPollLeaderboardSummary {
factory HMSPollLeaderboardSummary.fromMap(Map map) {
return HMSPollLeaderboardSummary(
averageScore: map["average_score"],
averageTime: Duration(milliseconds: map["average_time"].toInt()),
averageTime: map["average_time"] != null
? Duration(milliseconds: map["average_time"].toInt())
: null,
respondedCorrectlyPeersCount: map["responded_correctly_peers_count"],
respondedPeersCount: map["responded_peers_count"],
totalPeersCount: map["total_peers_count"]);
Expand Down

0 comments on commit 54ccb1b

Please sign in to comment.