'Flutter, stream builder in different screen can't access the data from stream
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.
Solution 1:[1]
@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");
}
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ke1212 |
