import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Material Components', home: FirstPage(), ); } } class FirstPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('第一页'), ), body: Padding( // padding: EdgeInsets.all(60.0), // padding: EdgeInsets.fromLTRB(0, 200, 30, 0), padding: EdgeInsets.only(top: 10,right: 30),// 指定任意方向的值 child: RaisedButton( child: Text('跳转到第二页'), onPressed: () { Navigator.push(//1 context, MaterialPageRoute(builder: (context) => SecondPage()), ); }, color: Color(0xfff1f433), ), ), ); } } class SecondPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('第二页'), ), body: Padding( padding: EdgeInsets.all(30.0), child: RaisedButton( child: Text('回到上一页'), onPressed: () { Navigator.pop(context);//2 }), ), ); } }
跑起来先