I tried adding data in flutter stream broadcast using text field input from user, after getting input added it to stream, tried displaying the text in different screen using stream builder. But stream builder prints null, If stream controller, sink.add event and stream builder is in same page (state). It works. I learnt I should make stream global so that stream builder in different screen can display data. How do I achieve that.
Asked
Active
Viewed 724 times
0
-
Please put the code in the question body, so the problem can be reproduce by users... – Wilson Toribio Apr 01 '22 at 12:28
-
Code is in this link https://stackoverflow.com/questions/71625932/flutter-stream-builder-returns-null – Ganesh Sivakumar Apr 01 '22 at 13:35
1 Answers
0
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, _verify);
}
void _verify() {
final _myBloc =BlocProvider.getBloc<MyBloc()_myBloc.myStream.listen((data) {
// Redirect to another view, given your condition
if (data) {
Navigator.of(context).pushNamed("my-new-route");
}
});
}

Ke1212
- 89
- 9
-
You can listen your stream outside of the build method and redirect to another view from there wherever you want to call. – Ke1212 Apr 01 '22 at 12:31