From 72603c2dd5dbe162664eb34bfd7f5cd2578bf037 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 13 Jan 2025 18:16:15 +0100 Subject: [PATCH 1/4] fix(ui): Fix StreamChannel not available in PollDialogs --- .../src/poll/stream_poll_comments_dialog.dart | 51 ++++++++++--------- .../poll/stream_poll_option_votes_dialog.dart | 27 +++++----- .../src/poll/stream_poll_options_dialog.dart | 9 ++-- .../src/poll/stream_poll_results_dialog.dart | 39 +++++++------- 4 files changed, 68 insertions(+), 58 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/poll/stream_poll_comments_dialog.dart b/packages/stream_chat_flutter/lib/src/poll/stream_poll_comments_dialog.dart index a5cc6a47b..0a4201262 100644 --- a/packages/stream_chat_flutter/lib/src/poll/stream_poll_comments_dialog.dart +++ b/packages/stream_chat_flutter/lib/src/poll/stream_poll_comments_dialog.dart @@ -21,31 +21,34 @@ Future showStreamPollCommentsDialog({ return navigator.push( MaterialPageRoute( fullscreenDialog: true, - builder: (_) => ValueListenableBuilder( - valueListenable: messageNotifier, - builder: (context, message, child) { - final poll = message.poll; - if (poll == null) return const SizedBox.shrink(); - - final channel = StreamChannel.of(context).channel; - - Future onUpdateComment() async { - final commentText = await showPollAddCommentDialog( - context: context, - // We use the first answer as the initial value because the - // user can only add one comment per poll. - initialValue: poll.ownAnswers.firstOrNull?.answerText ?? '', + builder: (_) => StreamChannel( + channel: StreamChannel.of(context).channel, + child: ValueListenableBuilder( + valueListenable: messageNotifier, + builder: (context, message, child) { + final poll = message.poll; + if (poll == null) return const SizedBox.shrink(); + + final channel = StreamChannel.of(context).channel; + + Future onUpdateComment() async { + final commentText = await showPollAddCommentDialog( + context: context, + // We use the first answer as the initial value because the + // user can only add one comment per poll. + initialValue: poll.ownAnswers.firstOrNull?.answerText ?? '', + ); + + if (commentText == null) return; + channel.addPollAnswer(message, poll, answerText: commentText); + } + + return StreamPollCommentsDialog( + poll: poll, + onUpdateComment: onUpdateComment, ); - - if (commentText == null) return; - channel.addPollAnswer(message, poll, answerText: commentText); - } - - return StreamPollCommentsDialog( - poll: poll, - onUpdateComment: onUpdateComment, - ); - }, + }, + ), ), ), ); diff --git a/packages/stream_chat_flutter/lib/src/poll/stream_poll_option_votes_dialog.dart b/packages/stream_chat_flutter/lib/src/poll/stream_poll_option_votes_dialog.dart index c174173f9..0c1040e72 100644 --- a/packages/stream_chat_flutter/lib/src/poll/stream_poll_option_votes_dialog.dart +++ b/packages/stream_chat_flutter/lib/src/poll/stream_poll_option_votes_dialog.dart @@ -20,19 +20,22 @@ Future showStreamPollOptionVotesDialog({ return navigator.push( MaterialPageRoute( fullscreenDialog: true, - builder: (_) => ValueListenableBuilder( - valueListenable: messageNotifier, - builder: (context, message, child) { - final poll = message.poll; - if (poll == null) return const SizedBox.shrink(); - if (option.id == null) return const SizedBox.shrink(); + builder: (_) => StreamChannel( + channel: StreamChannel.of(context).channel, + child: ValueListenableBuilder( + valueListenable: messageNotifier, + builder: (context, message, child) { + final poll = message.poll; + if (poll == null) return const SizedBox.shrink(); + if (option.id == null) return const SizedBox.shrink(); - return StreamPollOptionVotesDialog( - poll: poll, - option: option, - pollVotesCount: poll.voteCountsByOption[option.id], - ); - }, + return StreamPollOptionVotesDialog( + poll: poll, + option: option, + pollVotesCount: poll.voteCountsByOption[option.id], + ); + }, + ), ), ), ); diff --git a/packages/stream_chat_flutter/lib/src/poll/stream_poll_options_dialog.dart b/packages/stream_chat_flutter/lib/src/poll/stream_poll_options_dialog.dart index b855e6f0e..b5933c281 100644 --- a/packages/stream_chat_flutter/lib/src/poll/stream_poll_options_dialog.dart +++ b/packages/stream_chat_flutter/lib/src/poll/stream_poll_options_dialog.dart @@ -18,8 +18,9 @@ Future showStreamPollOptionsDialog({ return navigator.push( MaterialPageRoute( fullscreenDialog: true, - builder: (context) { - return ValueListenableBuilder( + builder: (_) => StreamChannel( + channel: StreamChannel.of(context).channel, + child: ValueListenableBuilder( valueListenable: messageNotifier, builder: (context, message, child) { final poll = message.poll; @@ -41,8 +42,8 @@ Future showStreamPollOptionsDialog({ onRemoveVote: onRemoveVote, ); }, - ); - }, + ), + ), ), ); } diff --git a/packages/stream_chat_flutter/lib/src/poll/stream_poll_results_dialog.dart b/packages/stream_chat_flutter/lib/src/poll/stream_poll_results_dialog.dart index 044cff139..2dc7e3103 100644 --- a/packages/stream_chat_flutter/lib/src/poll/stream_poll_results_dialog.dart +++ b/packages/stream_chat_flutter/lib/src/poll/stream_poll_results_dialog.dart @@ -29,26 +29,29 @@ Future showStreamPollResultsDialog({ return navigator.push( MaterialPageRoute( fullscreenDialog: true, - builder: (_) => ValueListenableBuilder( - valueListenable: messageNotifier, - builder: (context, message, child) { - final poll = message.poll; - if (poll == null) return const SizedBox.shrink(); + builder: (_) => StreamChannel( + channel: StreamChannel.of(context).channel, + child: ValueListenableBuilder( + valueListenable: messageNotifier, + builder: (context, message, child) { + final poll = message.poll; + if (poll == null) return const SizedBox.shrink(); - void onShowAllVotesPressed(PollOption option) { - showStreamPollOptionVotesDialog( - context: context, - messageNotifier: messageNotifier, - option: option, - ); - } + void onShowAllVotesPressed(PollOption option) { + showStreamPollOptionVotesDialog( + context: context, + messageNotifier: messageNotifier, + option: option, + ); + } - return StreamPollResultsDialog( - poll: poll, - visibleVotesCount: 5, - onShowAllVotesPressed: onShowAllVotesPressed, - ); - }, + return StreamPollResultsDialog( + poll: poll, + visibleVotesCount: 5, + onShowAllVotesPressed: onShowAllVotesPressed, + ); + }, + ), ), ), ); From 95deb44309418a2a3b0a91e74375bd835549f088 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 13 Jan 2025 18:18:17 +0100 Subject: [PATCH 2/4] chore: update CHANGELOG.md --- packages/stream_chat_flutter/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 8a3632fa3..c9e3fdbd7 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,3 +1,9 @@ +## Upcoming + +🐞 Fixed + +- Fixed `StreamChannel` not available in the widget tree for various Poll options. + ## 9.1.0 ✅ Added From a08c1c518a054a8c9dc51b1e4e155a061cdce476 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 13 Jan 2025 18:20:02 +0100 Subject: [PATCH 3/4] Update packages/stream_chat_flutter/CHANGELOG.md --- packages/stream_chat_flutter/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index c9e3fdbd7..9ef9b5e67 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -2,7 +2,7 @@ 🐞 Fixed -- Fixed `StreamChannel` not available in the widget tree for various Poll options. +- Fixed `StreamChannel` not available in the widget tree for various poll-related dialogs. ## 9.1.0 From e16558557bf965c0342b651998bf6c36f70d7fcf Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 13 Jan 2025 18:48:09 +0100 Subject: [PATCH 4/4] fix ci --- .github/workflows/stream_flutter_workflow.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/stream_flutter_workflow.yml b/.github/workflows/stream_flutter_workflow.yml index 2552a1435..5c97dcbe3 100644 --- a/.github/workflows/stream_flutter_workflow.yml +++ b/.github/workflows/stream_flutter_workflow.yml @@ -95,6 +95,9 @@ jobs: channel: stable cache: true cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }} + # This step is needed due to https://github.com/actions/runner-images/issues/11279 + - name: Install SQLite3 + run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev - name: "Install Tools" run: | flutter pub global activate melos