showStreamPollOptionsDialog<T extends Object?> function

Future<T?> showStreamPollOptionsDialog<T extends Object?>({
  1. required BuildContext context,
  2. required ValueListenable<Message> messageNotifier,
})

Displays an interactive dialog to show all the available options for a poll.

The dialog allows the user to cast a vote or remove a vote.

Implementation

Future<T?> showStreamPollOptionsDialog<T extends Object?>({
  required BuildContext context,
  required ValueListenable<Message> messageNotifier,
}) {
  final navigator = Navigator.of(context);
  return navigator.push(
    MaterialPageRoute(
      fullscreenDialog: true,
      builder: (context) {
        return ValueListenableBuilder(
          valueListenable: messageNotifier,
          builder: (context, message, child) {
            final poll = message.poll;
            if (poll == null) return const SizedBox.shrink();

            final channel = StreamChannel.of(context).channel;

            void onCastVote(PollOption option) {
              channel.castPollVote(message, poll, option);
            }

            void onRemoveVote(PollVote vote) {
              channel.removePollVote(message, poll, vote);
            }

            return StreamPollOptionsDialog(
              poll: poll,
              onCastVote: onCastVote,
              onRemoveVote: onRemoveVote,
            );
          },
        );
      },
    ),
  );
}