From 54ccb1bc82a27bcc8480c308219ea872ce6174ec Mon Sep 17 00:00:00 2001 From: Pushpam <93931528+Decoder07@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:10:38 +0530 Subject: [PATCH] user name is not getting displayed properly in poll bottom sheet (#1732) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed participants list bug * 🤖 Automated Format and Fix --------- Co-authored-by: Decoder07 --- .../bottom_sheets/poll_vote_bottom_sheet.dart | 17 ++++++++++++++--- .../lib/src/model/polls/hms_poll_answer.dart | 9 +++++---- .../polls/hms_poll_leaderboard_summary.dart | 4 +++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/poll_vote_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/poll_vote_bottom_sheet.dart index baf941eda..27d2cbf92 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/poll_vote_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/poll_vote_bottom_sheet.dart @@ -107,6 +107,18 @@ class _PollVoteBottomSheetState extends State { } } + 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(); @@ -176,9 +188,8 @@ class _PollVoteBottomSheetState extends State { ), ), 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, ), diff --git a/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_answer.dart b/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_answer.dart index 7e00f466c..990dac0c4 100644 --- a/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_answer.dart +++ b/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_answer.dart @@ -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; @@ -14,7 +14,7 @@ class HMSPollAnswer { HMSPollAnswer({ this.answerText, - required this.duration, + this.duration, required this.questionId, required this.questionType, this.selectedOption, @@ -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']), @@ -44,7 +45,7 @@ class HMSPollAnswer { Map toMap() { return { 'answer': answerText, - 'duration': duration.inSeconds, + 'duration': duration?.inSeconds, 'question_id': questionId, 'question_type': questionType.toString(), 'selected_option': selectedOption, diff --git a/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_leaderboard_summary.dart b/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_leaderboard_summary.dart index fc759f355..d8c0092e7 100644 --- a/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_leaderboard_summary.dart +++ b/packages/hmssdk_flutter/lib/src/model/polls/hms_poll_leaderboard_summary.dart @@ -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"]);