navigator pushreplacementnamed parameters

Solutions on MaxInterview for navigator pushreplacementnamed parameters by the best coders in the world

showing results for - "navigator pushreplacementnamed parameters"
Anton
19 Aug 2017
1import 'package:flutter/material.dart';
2
3void main() => runApp(new MyApp());
4
5class MyApp extends StatelessWidget {
6  @override
7  Widget build(BuildContext context) {
8    return new MaterialApp(
9      theme: new ThemeData(
10        primarySwatch: Colors.blue,
11      ),
12      home: new MyHomePage(),
13      routes: <String, WidgetBuilder> {
14        '/form': (BuildContext context) => new FormPage(), //new
15      },
16    );
17  }
18}
19
20class MyHomePage extends StatefulWidget {
21  @override
22  _MyHomePageState createState() => new _MyHomePageState();
23}
24
25class _MyHomePageState extends State<MyHomePage> {
26  @override
27  Widget build(BuildContext context) {
28    return new Scaffold(
29      floatingActionButton: new FloatingActionButton(
30        onPressed: () {
31          Navigator.of(context).pushReplacement(                                                         //new
32            new MaterialPageRoute(                                                                       //new
33              settings: const RouteSettings(name: '/form'),                                              //new
34              builder: (context) => new FormPage(email: 'myemail@flutter.com', header: {'auth': '1234'}) //new
35            )                                                                                            //new
36          );                                                                                             //new
37        },
38        child: new Icon(Icons.navigate_next),
39      ),
40    );
41  }
42}
43
44class FormPage extends StatefulWidget {
45  FormPage({Key key, this.email, this.header}) : super(key: key);
46  String email;
47  Map header;
48  @override
49  FormPageState createState() => new FormPageState();
50}
51
52class FormPageState extends State<FormPage> {
53  @override
54  Widget build(BuildContext context) {
55    return new Container(
56      child: new Column(
57        children: <Widget>[
58          new Text(widget.email),
59          new Text(widget.header['auth'])
60        ],
61      ),
62    );
63  }
64}
65