68 lines
2.4 KiB
Dart
68 lines
2.4 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
|
|
|
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
|
|
import '../../../../utils/UrlOpener.dart';
|
|
|
|
class PollOptionsList extends StatefulWidget {
|
|
final GetPollStateResponseObject pollData;
|
|
final String chatToken;
|
|
const PollOptionsList({super.key, required this.pollData, required this.chatToken});
|
|
|
|
@override
|
|
State<PollOptionsList> createState() => _PollOptionsListState();
|
|
}
|
|
|
|
class _PollOptionsListState extends State<PollOptionsList> {
|
|
@override
|
|
Widget build(BuildContext context) => Column(
|
|
children: [
|
|
...widget.pollData.options.map<Widget>((option) {
|
|
var optionId = widget.pollData.options.indexOf(option);
|
|
var votedSelf = widget.pollData.votedSelf.contains(optionId);
|
|
var portionsVisible = widget.pollData.votes is Map<String, dynamic>;
|
|
var votes = portionsVisible
|
|
? (widget.pollData.votes['option-$optionId'] as num?) ?? 0
|
|
: 0;
|
|
var numVoters = widget.pollData.numVoters ?? 0;
|
|
double portion = numVoters == 0 ? 0 : (votes / numVoters);
|
|
|
|
return ListTile(
|
|
// enabled: false,
|
|
isThreeLine: portionsVisible,
|
|
dense: true,
|
|
title: Text(
|
|
option,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
leading: Icon(
|
|
votedSelf ? Icons.check_circle_outlined : Icons.circle_outlined,
|
|
color: votedSelf
|
|
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.6)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
|
|
),
|
|
subtitle: portionsVisible ? Row(
|
|
children: [
|
|
Expanded(
|
|
child: LinearProgressIndicator(value: portion.clamp(0.0, 1.0)),
|
|
),
|
|
Container(
|
|
margin: const EdgeInsets.only(left: 10),
|
|
child: Text('${(portion * 100).round()}%'),
|
|
),
|
|
],
|
|
) : null,
|
|
);
|
|
}),
|
|
ListTile(
|
|
title: Linkify(
|
|
text: 'Wenn du abstimmen möchtest, verwende die Webversion unter https://cloud.marianum-fulda.de/call/${widget.chatToken}',
|
|
onOpen: UrlOpener.onOpen,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|