Flutter界面跳转

Flutter界面跳转

定义界面,有点像Android清单文件中申明界面。

可以新建个dart文件,声明

const first = 'first';
const two = 'two';
const three = 'three';

var RoutPath ={
  "$first":(context)=>  FirstScreen("AAAAA"),
  "$two":(context)=>  Second(),
  "$three":(context)=>  ThreeScreen(),
};

再跳转的时候可以这样调用

Navigator.pushNamed(context, 'first');

然后调用返回

Navigator.pop(context);

跳转方法以及含义

//未声明的正常启动
Navigator.push(context, MaterialPageRoute(builder: (context) => Second()));

//销毁所有的界面,并且跳转到first界面
Navigator.pushNamedAndRemoveUntil(context, 'first', (Route<dynamic> route) => false);

// 销毁除了 two 之外的所有界面
Navigator.pushNamedAndRemoveUntil(context, 'two', ModalRoute.withName('two'));

//跳转并替换当前界面
Navigator.pushReplacementNamed(context, "first");

//跳转并销毁当前界面
Navigator.popAndPushNamed(context, "first");

跳转界面并且传值

Navigator.push(context, new MaterialPageRoute(builder: (context)=> FirstScreen("我给你传值A")));

跳转界面获取传入值

String title ;
FirstScreen(String k){
    this.title = k;
}

跳转界面,并且获取返回的值

Navigator.pushNamed(context, 'three').then((Object o) {
                  print('我收到的返回值$o');
                });

返回界面,并且传递返回值

Navigator.pop(context, '给你的返回值333');

github地址:https://github.com/13522280478/FlutterTest

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值