美文网首页工作生活
flutter-动态路由

flutter-动态路由

作者: iPhone | 来源:发表于2019-07-01 15:25 被阅读0次

A

import 'package:flutter/material.dart';
import 'package:flutter_app_19_router/DynamicNaviattionPage.dart';


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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('A'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            MaterialButton(onPressed: (){
              Navigator.push(context, MaterialPageRoute(builder: (_) => DynamicNaviattionPage(
                username: 'zhaojie',
                password: '123456',
              ))).then((val){
                showDialog(context: context,
                  child: AlertDialog(
                    content: Text(val),
                  )
                );
              });
            },child: Text('push'),),
          ],
        ),
      ),
    );
  }
}

B

import 'package:flutter/material.dart';

class DynamicNaviattionPage extends StatelessWidget {
  var username;
  var password;
  DynamicNaviattionPage({
    Key key,
    this.username,
    this.password,
  }) : super(key : key);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('B 页面'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            MaterialButton(onPressed: (){
              Navigator.pop(context,'返回的数据');
            },
            child: Text('返回'),
            color: Colors.red,),
            Text('username: $username'),
            SizedBox(height: 20,),
            Text('密码: $password'),
          ],
        ),
      ),
    );
  }
}

相关文章

网友评论

    本文标题:flutter-动态路由

    本文链接:https://www.haomeiwen.com/subject/mvigcctx.html