【发布时间】:2021-01-22 05:09:45
【问题描述】:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyNavigationBar(),
);
}
}
class MyNavigationBar extends StatefulWidget {
@override
_MyNavigationBarState createState() => _MyNavigationBarState();
}
class _MyNavigationBarState extends State<MyNavigationBar> {
int _currentIndex = 0;
// all pages
final List<Widget> _children = [
ListScreen(),
HomaPage(),
FourthScreen(),
ThirdScreen(),
];
void OnTappedBar(int index){
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedItemColor: Colors.black,
unselectedItemColor: Colors.grey,
onTap: OnTappedBar,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("accueil")),
BottomNavigationBarItem(icon: Icon(Icons.search), title: Text("recherche")),
BottomNavigationBarItem(icon: Icon(Icons.calendar_today), title: Text("Mess Pass")),
BottomNavigationBarItem(icon: Icon(Icons.person), title: Text("Mon Profil")),
],
),
);
}
}
请!谁能告诉我bottomNavigationBar如何出现在所有页面上。
当我在任何页面上单击 Scaffold 中的 Flat 按钮时,底部应用栏会隐藏,但是当我使用底部应用栏项目在其他页面上导航时,底部应用栏不会消失。那么我该如何解决这个问题。我希望底部应用栏出现在所有页面上,即使我使用脚手架中的按钮导航或底部应用栏项目???
【问题讨论】:
-
你是否在
FlatButton'sonPressed方法中使用Navigator? -
@_ASAD HAMEED 是的,我使用导航器
-
编辑了我的答案并添加了更多实施细节。试一试:)
标签: flutter bottomnavigationview flutter-navigation flutter-bottomnavigation