当前位置: 代码迷 >> 综合 >> Flutter 页面跳转返回数据
  详细解决方案

Flutter 页面跳转返回数据

热度:145   发布时间:2023-09-07 07:14:38.0
import 'package:flutter/material.dart';class Product{final String title;final String description; //描述Product(this.title,this.description);
}void main(){runApp(MaterialApp(title:'页面跳转返回数据',home:FirstPage(),));
}class FirstPage extends StatelessWidget {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text('点餐'),),body: Center(child:RouteButton(),),);}
}class RouteButton extends StatelessWidget {@overrideWidget build(BuildContext context) {return RaisedButton(//onPressed 类似点击事件onPressed: (){_navigateToDianCan(context);},child: Text('去点餐'),);}
}//async 异步方法
_navigateToDianCan(BuildContext context) async{final result = await Navigator.push(context, MaterialPageRoute(builder: (context)=>DianCan()));Scaffold.of(context).showSnackBar(SnackBar(content:Text('$result')));
}class DianCan extends StatelessWidget {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text('菜品页'),),body: Center(child: Column(children: <Widget>[RaisedButton(child: Text('宫爆鸡丁'),onPressed: (){Navigator.pop(context,'宫爆鸡丁:15元');},),RaisedButton(child: Text('三鲜面'),onPressed: (){Navigator.pop(context,'三鲜面:13元');},),],),),);}
}

 

  相关解决方案