My question is about navigation used with the BLoC pattern.
In my LoginScreen widget I have a button that adds an event into the EventSink of the bloc. The bloc calls the API and authenticates the user. Where in the LoginScreen Widget do I have to listen to the stream, and how do I navigate to another screen after it returns a success status?
This is using context and sometimes we find shortcuts to do the task easily. For that, we have Get. back() in flutter. We can send the result to the previous route and do the operations.
Bloc is a good pattern that will be suitable for almost all types of apps. It helps improve the code's quality and makes handling states in the app much more manageable. It might be challenging for someone who is just beginning to use Flutter because it uses advanced techniques like Stream and Reactive Programming.
Use BlockListener.
BlocListener( bloc: _yourBloc, listener: (BuildContext context, YourState state) { if(state is NavigateToSecondScreen){ Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {return SecondScreen();})); } }, child: childWidget )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With