Flutter中多页面开发,主要涉及:Route 和 Navigator。路由(Route)是应用程序的“屏幕”或“页面”的抽象,导航器(Navigator)是管理路由的控件。导航器(Navigator)可以推送(push)和弹出(pop)路由来帮助用户从当前屏幕移动到另一个屏幕。
演示代码:
跳转其他页面(方案一):
Java
onPressed context builder context title
跳转其他页面(方案二):
1、先在routes中定义路由名称,对应跳转的页面:
Java
routes context context title
2、处理点击事件,使用Navigator.pushNamed 进行跳转:
Java
onPressed context
下面是完整的调转代码,其中补充了FloatingActionButton的一些属性的介绍:
Java
context debugShowCheckedModeBanner initialRoute routes context context title theme primaryColor deepPurple context appBar title style fontSize color deepOrange body child mainAxisAlignment center children child onPressed context width child onPressed title title context appBar title title elevation body child title floatingActionButton child home foregroundColor white backgroundColor deepPurple onPressed context
演示效果:
代码中TitleBar返回按钮的返回功能是系统默认的,FloatingActionButton的返回功能是自定义。
还没有评论,来说两句吧...