【发布时间】:2018-11-17 10:15:53
【问题描述】:
假设我点击标签“第 2 页”,然后点击“第 3 页”。现在,当我单击设备上的返回按钮时,我想返回“第 2 页”。
对我来说,应用程序关闭了。我是否使用了错误的小部件,或者我应该怎么做才能确保当用户使用设备上的后退按钮时,它会转到上一个选项卡而不是强制关闭应用程序。
class MovieRouting extends StatefulWidget {
@override
MovieRoutingState createState() => new MovieRoutingState();
}
// SingleTickerProviderStateMixin is used for animation
class MovieRoutingState extends State<MovieRouting> with SingleTickerProviderStateMixin {
int i = 0;
var pages = [new Page1(), new Page2(), new Page3(), new Page4()];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: pages[i],
// drawer: new AppNavigationDrawer(),
bottomNavigationBar: new BottomNavigationBar(
items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text('page 1'),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.photo_library),
title: new Text('page 2'),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.book),
title: new Text('page 3'),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.notifications),
title: new Text('page 4'),
),
],
currentIndex: i,
type: BottomNavigationBarType.fixed,
onTap: (index) {
print (index);
setState(() {
i = index;
});
},
),
);
}
}
【问题讨论】:
-
你必须使用嵌套的
Navigators -
您能提供一些示例代码的链接吗?
-
google("flutter nested navigators")
标签: dart flutter bottomnavigationview