Reputation: 77
I'm asking if bloc_flutter (Bloc pattern implementation for flutter), is the right solution to manage the app "navigation".
I used bloc_flutter to manage firebase login https://github.com/felangel/bloc/tree/master/examples/flutter_firebase_login.
After user successfully loggedin, he lands in a "welcome screen" with menu. I tried to manage screen navigation of this menu, using a new bloc pattern but it seems an overwhelming solution to me. Moreover, using navigation with bloc pattern doesn't let you use Android "back button".
So, would be better, in your opinion, using navigation of routes and let bloc manages the logic of each screen?
Upvotes: 1
Views: 471
Reputation: 705
No, it's not. If you want your application to have a good architecture, you should not use bloc in order to handle navigation since navigation is not something related to the application's business logic, it's a part of the UI.
Upvotes: 1
Reputation: 32529
I pass GlobalKey<NavigatorState>
to bloc and can perform navigation from there:
@override
Stream<MyScreenState> mapEventToState(
MyScreenEvent event,
) async* {
if (event is SomeEvent) {
_navigatorKey.currentState.push(...);
}
}
Note that this key needs to be used on MaterialApp
instantiation to get things working:
MaterialApp(
navigatorKey: _navigatorKey,
...
);
Upvotes: 0