45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../api/marianumcloud/talk/get_poll/get_poll_state.dart';
|
|
import '../../../../widget/loading_spinner.dart';
|
|
import 'poll_options_list.dart';
|
|
|
|
/// Opens the poll dialog that lets a user vote on a Talk poll attached to
|
|
/// a message. Loads the poll state lazily and renders the option list.
|
|
void showChatBubblePollDialog(
|
|
BuildContext context, {
|
|
required String chatToken,
|
|
required String messageToken,
|
|
required int pollId,
|
|
required String pollName,
|
|
}) {
|
|
final pollState = GetPollState(token: messageToken, pollId: pollId).run();
|
|
showDialog<void>(
|
|
context: context,
|
|
builder: (dialogCtx) => AlertDialog(
|
|
title: Text(pollName, overflow: TextOverflow.ellipsis),
|
|
content: FutureBuilder(
|
|
future: pollState,
|
|
builder: (_, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
|
|
}
|
|
final pollData = snapshot.data!.data;
|
|
return SingleChildScrollView(
|
|
child: PollOptionsList(
|
|
pollData: pollData,
|
|
chatToken: chatToken,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(dialogCtx).pop(),
|
|
child: const Text('Zurück'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|