【发布时间】:2020-06-06 19:48:29
【问题描述】:
我想在用户点击第四个(more_vert)图标时显示一个抽屉,但我无法实现它。在我当前的实现中,当单击第 4 个图标时,flutter 会将我带到一个新页面,并显示抽屉不在当前屏幕上。我究竟做错了什么 ?另外,BottomNavigationBar 和 BottomAppBar 之间的区别是什么,我在任何地方都找不到区别。我查看了几篇文章,我认为 BottomAppBar 用于显示 Fab 浮动在底部应用程序栏中。两者之间是否还有其他区别,何时应该使用一种而不是另一种。
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
List<Widget> _widgetOptions = <Widget>[
Page1(),
Page2(),
Page3(),
Page4(), // this page implements the drawer
];
int _currentSelected = 0;
void _onItemTapped(int index) {
setState(() {
_currentSelected = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _widgetOptions.elementAt(_currentSelected),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
currentIndex: _currentSelected,
showUnselectedLabels: true,
unselectedItemColor: Colors.grey[800],
selectedItemColor: Color.fromRGBO(10, 135, 255, 1),
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(AntDesign.carryout),
),
BottomNavigationBarItem(
icon: Icon(MaterialCommunityIcons.sack),
),
BottomNavigationBarItem(
icon: Icon(Octicons.archive),
),
BottomNavigationBarItem(
icon: Icon(Icons.more_vert),
)
],
),
// backgroundColor: Colors.black,
);
}
}
【问题讨论】:
-
你有没有检查过这个可以帮助你的链接:stackoverflow.com/questions/56007613/…