flutter 中页面跳转通过 Navigator提供的函数完成;例如:push ,pop ,replace ..。
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context){
return WelcomePage(null);
}));
MaterialPageRoute 就是 页面路由的实现。
如果 在项目中 很多页面跳转 都这样直接使用,会 非常麻烦 繁琐;那该如何解决呢?
去除 重复代码,做一层封装;使用注解 简化代码
借鉴 annotation_route
建立 url 和目标页面的 路由表,而且在 页面跳转封装的基础上 实现 url和widget的互相转换。
补充
路由监听 MaterialApp中的navigatorObservers
MaterialApp(
navigatorKey: navigatorKey,
navigatorObservers: [ARouter.observer],
initialRoute: 'welcome',
routes: {
'welcome': (context) => WelcomePage({}),
}
);