import 'package:flutter/material.dart';import 'package:flutter_app1/test.dart';void main() =>runApp(MyApp());class MyApp extendsStatelessWidget {//This widget is the root of your application.
@override
Widget build(BuildContext context) {returnMaterialApp(
title:'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title:'Flutter Demo'),
routes:{'/first_page': (BuildContext context) =>FirstPage(),
},
);
}
}class MyHomePage extendsStatefulWidget {
MyHomePage({Key key,this.title}) : super(key: key);finalString title;
@override
_MyHomePageState createState()=>_MyHomePageState();
}class _MyHomePageState extends State{//Default placeholder text
@override
Widget build(BuildContext context) {returnScaffold(
appBar: AppBar(
title: Text("Sample App"),
),
body: Center(
child:Container(
child:newColumn(
children:[new CustomButton("first_page","/first_page"),newRaisedButton(
child: Text("动态跳转"),
onPressed: dynamicJump,
)
],
),
margin: EdgeInsets.only(top:50, left: 20, right: 20),
)
)
);
}voiddynamicJump(){
Future future= Navigator.push(context,new MaterialPageRoute(builder: (context) => newFirstPage()));
future.then((value){
showDialog(
context: context,
builder: (context)=>AlertDialog(
title: Text('$value'),
));
});
}
}class CustomButton extendsStatelessWidget {finalString label;
String link;
CustomButton(this.label,this.link);
@override
Widget build(BuildContext context) {return
newContainer(
child:RaisedButton(onPressed: () {
Navigator.of(context).pushNamed(link);
}, child: Text(label,style:new TextStyle(height: 1),),
),
width:double.infinity,);
}
}