我正在使用Redux开发Flutter.
当用户启动一个应用程序,我想Redux自动dispatch的action.此操作将Navigator依赖于推送不同的路径.
此片段由颤振dev的部件提供使用该GlobalKey使用Navigator内middleware.
在此之后,我按如下方式组织我的代码:
main.dart
void main() {
final store = new Store(appStateReducer,
middleware:createRouteMiddleware()
);
runApp(new MyApp(store));
}
class MyApp extends StatelessWidget {
final Store<AppState> store;
MyApp(this.store);
@override
Widget build(BuildContext context) {
return new StoreProvider<AppState>(
store: store,
child: MaterialApp(
routes: {
Routes.REGISTER: (context) {
return RegisterScreenContainer();
},
Routes.SET_PROFILE: (context) {
return SetProfileScreenContainer();
},
//Routes.HOME = "/" so this route will be run first
Routes.HOME: …Run Code Online (Sandbox Code Playgroud)