Skip to content

Commit 3e95b11

Browse files
authored
fix(ui): fix StreamChannel not available in various poll dialogs (#2082)
1 parent b9871eb commit 3e95b11

File tree

6 files changed

+77
-58
lines changed

6 files changed

+77
-58
lines changed

.github/workflows/stream_flutter_workflow.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ jobs:
9595
channel: stable
9696
cache: true
9797
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
98+
# This step is needed due to https://github.com/actions/runner-images/issues/11279
99+
- name: Install SQLite3
100+
run: sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev
98101
- name: "Install Tools"
99102
run: |
100103
flutter pub global activate melos

packages/stream_chat_flutter/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Upcoming
2+
3+
🐞 Fixed
4+
5+
- Fixed `StreamChannel` not available in the widget tree for various poll-related dialogs.
6+
17
## 9.1.0
28

39
✅ Added

packages/stream_chat_flutter/lib/src/poll/stream_poll_comments_dialog.dart

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,34 @@ Future<T?> showStreamPollCommentsDialog<T extends Object?>({
2121
return navigator.push(
2222
MaterialPageRoute(
2323
fullscreenDialog: true,
24-
builder: (_) => ValueListenableBuilder(
25-
valueListenable: messageNotifier,
26-
builder: (context, message, child) {
27-
final poll = message.poll;
28-
if (poll == null) return const SizedBox.shrink();
29-
30-
final channel = StreamChannel.of(context).channel;
31-
32-
Future<void> onUpdateComment() async {
33-
final commentText = await showPollAddCommentDialog(
34-
context: context,
35-
// We use the first answer as the initial value because the
36-
// user can only add one comment per poll.
37-
initialValue: poll.ownAnswers.firstOrNull?.answerText ?? '',
24+
builder: (_) => StreamChannel(
25+
channel: StreamChannel.of(context).channel,
26+
child: ValueListenableBuilder(
27+
valueListenable: messageNotifier,
28+
builder: (context, message, child) {
29+
final poll = message.poll;
30+
if (poll == null) return const SizedBox.shrink();
31+
32+
final channel = StreamChannel.of(context).channel;
33+
34+
Future<void> onUpdateComment() async {
35+
final commentText = await showPollAddCommentDialog(
36+
context: context,
37+
// We use the first answer as the initial value because the
38+
// user can only add one comment per poll.
39+
initialValue: poll.ownAnswers.firstOrNull?.answerText ?? '',
40+
);
41+
42+
if (commentText == null) return;
43+
channel.addPollAnswer(message, poll, answerText: commentText);
44+
}
45+
46+
return StreamPollCommentsDialog(
47+
poll: poll,
48+
onUpdateComment: onUpdateComment,
3849
);
39-
40-
if (commentText == null) return;
41-
channel.addPollAnswer(message, poll, answerText: commentText);
42-
}
43-
44-
return StreamPollCommentsDialog(
45-
poll: poll,
46-
onUpdateComment: onUpdateComment,
47-
);
48-
},
50+
},
51+
),
4952
),
5053
),
5154
);

packages/stream_chat_flutter/lib/src/poll/stream_poll_option_votes_dialog.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@ Future<T?> showStreamPollOptionVotesDialog<T extends Object?>({
2020
return navigator.push(
2121
MaterialPageRoute(
2222
fullscreenDialog: true,
23-
builder: (_) => ValueListenableBuilder(
24-
valueListenable: messageNotifier,
25-
builder: (context, message, child) {
26-
final poll = message.poll;
27-
if (poll == null) return const SizedBox.shrink();
28-
if (option.id == null) return const SizedBox.shrink();
23+
builder: (_) => StreamChannel(
24+
channel: StreamChannel.of(context).channel,
25+
child: ValueListenableBuilder(
26+
valueListenable: messageNotifier,
27+
builder: (context, message, child) {
28+
final poll = message.poll;
29+
if (poll == null) return const SizedBox.shrink();
30+
if (option.id == null) return const SizedBox.shrink();
2931

30-
return StreamPollOptionVotesDialog(
31-
poll: poll,
32-
option: option,
33-
pollVotesCount: poll.voteCountsByOption[option.id],
34-
);
35-
},
32+
return StreamPollOptionVotesDialog(
33+
poll: poll,
34+
option: option,
35+
pollVotesCount: poll.voteCountsByOption[option.id],
36+
);
37+
},
38+
),
3639
),
3740
),
3841
);

packages/stream_chat_flutter/lib/src/poll/stream_poll_options_dialog.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Future<T?> showStreamPollOptionsDialog<T extends Object?>({
1818
return navigator.push(
1919
MaterialPageRoute(
2020
fullscreenDialog: true,
21-
builder: (context) {
22-
return ValueListenableBuilder(
21+
builder: (_) => StreamChannel(
22+
channel: StreamChannel.of(context).channel,
23+
child: ValueListenableBuilder(
2324
valueListenable: messageNotifier,
2425
builder: (context, message, child) {
2526
final poll = message.poll;
@@ -41,8 +42,8 @@ Future<T?> showStreamPollOptionsDialog<T extends Object?>({
4142
onRemoveVote: onRemoveVote,
4243
);
4344
},
44-
);
45-
},
45+
),
46+
),
4647
),
4748
);
4849
}

packages/stream_chat_flutter/lib/src/poll/stream_poll_results_dialog.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,29 @@ Future<T?> showStreamPollResultsDialog<T extends Object?>({
2929
return navigator.push(
3030
MaterialPageRoute(
3131
fullscreenDialog: true,
32-
builder: (_) => ValueListenableBuilder(
33-
valueListenable: messageNotifier,
34-
builder: (context, message, child) {
35-
final poll = message.poll;
36-
if (poll == null) return const SizedBox.shrink();
32+
builder: (_) => StreamChannel(
33+
channel: StreamChannel.of(context).channel,
34+
child: ValueListenableBuilder(
35+
valueListenable: messageNotifier,
36+
builder: (context, message, child) {
37+
final poll = message.poll;
38+
if (poll == null) return const SizedBox.shrink();
3739

38-
void onShowAllVotesPressed(PollOption option) {
39-
showStreamPollOptionVotesDialog(
40-
context: context,
41-
messageNotifier: messageNotifier,
42-
option: option,
43-
);
44-
}
40+
void onShowAllVotesPressed(PollOption option) {
41+
showStreamPollOptionVotesDialog(
42+
context: context,
43+
messageNotifier: messageNotifier,
44+
option: option,
45+
);
46+
}
4547

46-
return StreamPollResultsDialog(
47-
poll: poll,
48-
visibleVotesCount: 5,
49-
onShowAllVotesPressed: onShowAllVotesPressed,
50-
);
51-
},
48+
return StreamPollResultsDialog(
49+
poll: poll,
50+
visibleVotesCount: 5,
51+
onShowAllVotesPressed: onShowAllVotesPressed,
52+
);
53+
},
54+
),
5255
),
5356
),
5457
);

0 commit comments

Comments
 (0)