状态更改后如何路由到不同的屏幕?
How to route to a different screen after a state change?
我正在使用 flutter_redux 和 google_sign_in,我想在登录后从登录页面转到另一个页面。
我正在使用调度 LoggedInSuccessfully
操作的中间件处理对 Google 的 API 调用。我知道我可以使用 Navigator.pushNamed(context, "/routeName")
进行实际路由,但我是 Flutter 和 Redux 的新手,我的问题是我只是不知道 在哪里 调用它。
下面的代码是针对 GoogleAuthButtonContainer
的,这是我对路由位置的猜测。 GoogleAuthButton
只是一个带有实际按钮和布局的普通小部件。
感谢任何帮助,谢谢!
@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());
}
});
}
}
我正在使用 flutter_redux 和 google_sign_in,我想在登录后从登录页面转到另一个页面。
我正在使用调度 LoggedInSuccessfully
操作的中间件处理对 Google 的 API 调用。我知道我可以使用 Navigator.pushNamed(context, "/routeName")
进行实际路由,但我是 Flutter 和 Redux 的新手,我的问题是我只是不知道 在哪里 调用它。
下面的代码是针对 GoogleAuthButtonContainer
的,这是我对路由位置的猜测。 GoogleAuthButton
只是一个带有实际按钮和布局的普通小部件。
感谢任何帮助,谢谢!
@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());
}
});
}
}