导航
-
main.dart
代码:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main(){
runApp(MaterialApp(
title: "导航01",
home: new FirstScreen()
));
}
class FirstScreen extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('导航页面'),
),
body: Center(
child: RaisedButton( // 凸起的按钮
child: Text('查看商品详情页'),
onPressed: (){
Navigator.push(context, MaterialPageRoute(
builder: (context) => new SecondScreen()
));
},
),
)
);
}
}
class SecondScreen extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Link 商品详情页'),),
body: Center(
child: RaisedButton(
child: Text('返回'),
onPressed: (){
Navigator.pop(context);
},
),
)
);
}
}
【效果】如下:
首页
点击之后的页面
网友评论