0

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.

Ganesh Sivakumar
  • 149
  • 1
  • 16

1 Answers1

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