Reputation: 3454
I'm using flutter_redux and google_sign_in and I want to route from the Login page to a different page after logging in.
I am handling the API call to Google using middleware that dispatches a LoggedInSuccessfully
action. I know I can use Navigator.pushNamed(context, "/routeName")
for the actual routing, but I am new to both Flutter and Redux and my problem is that I just don't know where to call this.
The code below is for the GoogleAuthButtonContainer
, which is my guess as to where the routing should be. The GoogleAuthButton
is just a plain widget with the actual button and layout.
Any help appreciated, thanks!
@override
Widget build(BuildContext context) {
return new StoreConnector<AppState, _ViewModel>(
converter: _ViewModel.fromStore,
builder: (BuildContext context, _ViewModel vm) {
return new GoogleAuthButton(
buttonText: vm.buttonText,
onPressedCallback: vm.onPressedCallback,
);
},
);
}
}
class _ViewModel {
final String buttonText;
final Function onPressedCallback;
_ViewModel({this.onPressedCallback, this.buttonText});
static _ViewModel fromStore(Store<AppState> store) {
return new _ViewModel(
buttonText:
store.state.currentUser != null ? 'Log Out' : 'Log in with Google',
onPressedCallback: () {
if (store.state.currentUser != null) {
store.dispatch(new LogOut());
} else {
store.dispatch(new LogIn());
}
});
}
}
Upvotes: 10
Views: 3258
Reputation: 1419
You can achieve this by 3 different ways:
navigatorKey
and use it in a Middleware
as described hereNavigator
to the Action
class and use it in the Middleware
So to sum up, you probably want to use a Middleware
to do the navigation.
Upvotes: 10