71 lines
2.5 KiB
Dart
71 lines
2.5 KiB
Dart
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
|
|
|
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
|
|
|
|
class PollOptionsList extends StatefulWidget {
|
|
final GetPollStateResponseObject pollData;
|
|
const PollOptionsList({super.key, required this.pollData});
|
|
|
|
@override
|
|
State<PollOptionsList> createState() => _PollOptionsListState();
|
|
}
|
|
|
|
class _PollOptionsListState extends State<PollOptionsList> {
|
|
@override
|
|
Widget build(BuildContext context) => Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
...widget.pollData.options.map<Widget>((option) {
|
|
var optionId = widget.pollData.options.indexOf(option);
|
|
var votedSelf = widget.pollData.votedSelf.contains(optionId);
|
|
var votes = widget.pollData.votes.runtimeType is Map<String, dynamic>
|
|
? widget.pollData.votes['option-$optionId']
|
|
: 0;
|
|
int numVoters = 1;
|
|
if(widget.pollData.numVoters != null && widget.pollData.numVoters != 0) {
|
|
numVoters = widget.pollData.numVoters!;
|
|
}
|
|
var portion = (votes / numVoters);
|
|
return ListTile(
|
|
enabled: false,
|
|
isThreeLine: true,
|
|
title: Text(
|
|
option,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
trailing: Icon(
|
|
votedSelf ? Icons.check_circle_outlined : Icons.circle_outlined,
|
|
color: votedSelf
|
|
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.8)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant.withValues(alpha: 0.8),
|
|
),
|
|
subtitle: Visibility(
|
|
visible: widget.pollData.numVoters != null,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: LinearProgressIndicator(value: portion),
|
|
),
|
|
Container(
|
|
margin: const EdgeInsets.only(left: 10),
|
|
child: Text('${(portion * 100).round()}%'),
|
|
),
|
|
],
|
|
)
|
|
)
|
|
);
|
|
}),
|
|
ListTile(
|
|
title: Linkify(
|
|
text: 'Zurzeit kann in dieser App leider nicht an Abstimmungen teilgenommen werden. '
|
|
'Um abzustimmen verwende die Webversion unter https://cloud.marianum-fulda.de',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|