天天看点

传参~

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 {

builder: (context) => pagecontentbuilder(context));

}

});

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

)

// 3、接收参数

import 'package:flutter/material.dart';

class formpage extends statelesswidget {

final map arguments;

formpage({this.arguments});

return scaffold(

appbar: appbar(

title: text("搜索"),

),

body:text("我是一个表单页面 ${arguments != null ? arguments['id'] : '0'}")

);

————————————————