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'),
],
),
),
);
}
}
网友评论