getPollBar method
Widget
getPollBar(
- int index,
- String id,
- List<
PollOptions> options, - int totalVote,
- String chosenId,
- String pollId,
- CometChatTheme theme,
Implementation
Widget getPollBar(int index, String id, List<PollOptions> options,
int totalVote, String chosenId, String pollId, CometChatTheme theme) {
int count = options[index].voteCount;
String text = options[index].optionText;
double percentage = totalVote == 0 ? 0 : (count / totalVote * 100);
Color progressColor =
style?.unSelectedOptionColor ?? theme.palette.getAccent100();
Color background =
style?.pollOptionsBackgroundColor ?? theme.palette.getBackground();
if (id == chosenId) {
progressColor =
style?.selectedOptionColor ?? theme.palette.getPrimary200();
}
return Padding(
padding: const EdgeInsets.only(bottom: 6.0, right: 4, left: 4),
child: GestureDetector(
onTap: () {
if (loggedInUser != null &&
senderUid != null &&
senderUid == loggedInUser) {
return;
}
int previousChosen = options
.indexWhere((PollOptions element) => element.id == chosenId);
if (previousChosen != -1) {
options[previousChosen].voteCount--;
} else {
totalVote++;
}
chosenId = id;
options[index].voteCount++;
choosePoll(id, pollId);
},
child: Stack(
alignment: Alignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(6.0),
child: LinearProgressIndicator(
backgroundColor: background,
minHeight: 42,
value: percentage / 100,
valueColor: AlwaysStoppedAnimation<Color>(progressColor),
)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 7,
child: Padding(
padding: const EdgeInsets.only(left: 11),
child: Text(
text,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: theme.typography.subtitle1.fontSize,
fontWeight:
theme.typography.subtitle1.fontWeight,
fontFamily:
theme.typography.subtitle1.fontFamily,
color: theme.palette.getAccent())
.merge(style?.pollOptionsTextStyle),
),
)),
Flexible(
flex: 3,
child: Padding(
padding: const EdgeInsets.only(right: 11),
child: Text(
"${percentage.toStringAsFixed(1)}%",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: theme.typography.subtitle2.fontSize,
fontWeight:
theme.typography.subtitle2.fontWeight,
fontFamily:
theme.typography.subtitle2.fontFamily,
color: theme.palette.getAccent600())
.merge(style?.pollResultTextStyle),
),
)),
],
)
],
),
),
);
}