import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(body: HomePage())
));
}
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.red,
child: Center(
child:RaisedButton(
child:Text('push'),
onPressed:(){
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => Page2())
);
})
)
);
}
}
class Page2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.green,
child: Center(
child:RaisedButton(
child:Text('pop'),
onPressed:(){
Navigator.pop(context);
})
)
)
);
}
}
网友评论