changed poll dialog to only show results

This commit is contained in:
2026-02-01 03:23:36 +01:00
parent 699aec8ab5
commit 3469d02033
5 changed files with 103 additions and 87 deletions

View File

@@ -1,45 +1,69 @@
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;
final Function(List<int>) callback;
const PollOptionsList({super.key, required this.pollData, required this.callback});
const PollOptionsList({super.key, required this.pollData});
@override
State<PollOptionsList> createState() => _PollOptionsListState();
}
class _PollOptionsListState extends State<PollOptionsList> {
late List<int> ownVotes;
@override
void initState() {
super.initState();
ownVotes = widget.pollData.votedSelf;
}
@override
Widget build(BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: [
...widget.pollData.options.map<Widget>((option) => CheckboxListTile(
value: ownVotes.contains(widget.pollData.options.indexOf(option)),
title: Text(option),
onChanged: (value) {
var optionId = widget.pollData.options.indexOf(option);
setState(() {
if(ownVotes.contains(optionId)) {
ownVotes.remove(optionId);
} else {
ownVotes.add(optionId);
}
});
widget.callback(ownVotes);
}
)
...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,
),
)
],
);