Parameter passing ~

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 is
13 is
14
15
16
. 17
18 is
. 19
20 is
21 is
22 is
23 is
24
25
26 is
27
28
29
30
31 is
32
33 is
34 is
35
36
37 [
38 is
// 2, the value of the jump pass
RaisedButton (
Child: Text ( "jump to page presentation form"),
onPressed: (http://www.amjmh.com) {
Navigator.pushNamed (context, '/ form', arguments: {
"ID": 20 is
});
},
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';

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

@override
the Widget Build (BuildContext context) {
return the Scaffold (
appbar: the AppBar (
title: the Text ( "search"),
),
body: the Text ( " I am a form page $ {arguments = null arguments [ ' id']:!? '0'} ")

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

Guess you like

Origin www.cnblogs.com/ly570/p/11402902.html