传参~

import 'pages/Form.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
final routes = {
'/': (contxt) => Tabs(),
'/search': (contxt) => SearchPage(),
'/form': (context, {arguments}) => FormPage(arguments: arguments),
};

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Tabs(),
onGenerateRoute: (RouteSettings settings) {
// 统一处理
final String name = settings.name;
final Function pageContentBuilder = this.routes[name];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context,
arguments: settings.arguments));
return route;
} else {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context));
return route;
}
}
});
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 2、跳转传值
RaisedButton(
child: Text("跳转到表单演示页面"),
onPressed: (http://www.amjmh.com){
Navigator.pushNamed(context, '/form',arguments: {
"id":20
});
},
color: Theme.of(context).accentColor,
textTheme: ButtonTextTheme.primary
)
1
2
3
4
5
6
7
8
9
10
11
// 3、接收参数
import 'package:flutter/material.dart';

class FormPage extends StatelessWidget {
final Map arguments;
FormPage({this.arguments});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("搜索"),
),
body:Text("我是一个表单页面 ${arguments != null ? arguments['id'] : '0'}")

);
}
}
————————————————

posted on 2019-08-23 22:05  激流勇进1  阅读(110)  评论(0编辑  收藏  举报