Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user name is not getting displayed properly in poll bottom sheet #1732

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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