Navigator(
initialRoute: '/',onGenerateRoute: (RouteSettings settings) {
WidgetBuilder builder;
switch (settings.name) {
case 'home':
builder = (context) => PageA();
break;
case 'user':
builder = (context) => PageB();
break;
}
return MaterialPageRoute(builder: builder,settings: settings);
},)
@override
Widget build(BuildContext context) {
return Center(
child: Container(
height: 350,width: 300,child: Navigator(
initialRoute: '/',onGenerateRoute: (RouteSettings settins) {
WidgetBuilder builder;
switch (settins.name) {
case '/':
builder = (context) => PageC();
break;
}
return MaterialPageRoute(builder: builder);
},),);
}
class PageC extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Card(
child: Column(
children: <Widget>[
_buildItem(Icons.clear,'不感兴趣','减少这类内容'),Divider(),_buildItem(Icons.access_alarm,'举报','标题夸张,内容质量差 等',showArrow: true,onPress: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return PageD();
}));
}),_buildItem(Icons.perm_identity,'拉黑作者:新华网客户端',''),_buildItem(Icons.account_circle,'屏蔽','军事视频、驾驶员等'),],);
}
_buildItem(IconData iconData,String title,String content,{bool showArrow = false,Function onPress}) {
return Row(
children: <Widget>[
Icon(iconData),SizedBox(
width: 20,Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
Text(
title,style: TextStyle(fontSize: 18),Text(
content,style: TextStyle(
color: Colors.black.withOpacity(.5),fontSize: 14),)
],!showArrow
? Container()
: IconButton(
icon: Icon(Icons.arrow_forward_ios),iconSize: 16,onPressed: onPress,);
}
}
class PageD extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 200,width: 250,color: Colors.grey.withOpacity(.5),child: Column(
children: <Widget>[
Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios),onPressed: () {
Navigator.of(context).pop();
},Text('返回'),SizedBox(
width: 30,Text('举报'),);
}
}
class TabMain extends StatefulWidget {
@override
State<StatefulWidget> createState() => _TabMainState();
}
class _TabMainState extends State<TabMain> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,children: <Widget>[
TabNavigator(0),TabNavigator(1),TabNavigator(2),bottomNavigationBar: BottomNavigationBar(
onTap: (int index) {
setState(() {
_currentIndex = index;
});
},currentIndex: _currentIndex,items: <BottomNavigationBarItem>[
BottomNavigationBarItem(title: Text('首页'),icon: Icon(Icons.home)),BottomNavigationBarItem(title: Text('书籍'),icon: Icon(Icons.book)),BottomNavigationBarItem(
title: Text('我的'),icon: Icon(Icons.perm_identity)),);
}
}
class TabNavigator extends StatelessWidget {
TabNavigator(this.index);
final int index;
@override
Widget build(BuildContext context) {
return Navigator(
initialRoute: '/',onGenerateRoute: (RouteSettings settins) {
WidgetBuilder builder;
switch (settins.name) {
case '/':
builder = (context) => ListPage(index);
break;
}
return MaterialPageRoute(builder: builder);
},);
}
}
class ListPage extends StatelessWidget {
ListPage(this.index);
final int index;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),body: Center(
child: RaisedButton(
child: Text('$index'),onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return DetailPage();
}));
},);
}
}
class DetailPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),body: Center(
child: Text('DetailPage'),);
}
}