我正在尝试在导航栏项目被点击时显示一个菜单。这是我的尝试:
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: MyAppBar(
title: "Home",
context: context,
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(
icon: new Icon(Icons.book), title: Text('Second')),
BottomNavigationBarItem(
icon: new PopupMenuButton(
icon: Icon(Icons.add),
itemBuilder: (_) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
child: const Text('test1'), value: 'test1'),
new PopupMenuItem<String>(
child: const Text('test2'), value: 'test2'),
],
),
title: Text('more')),
],
currentIndex: 0,
),
body: new Container()));
}
我遇到了两个问题。第一个是NavigationBarItem的显示。在图标和标题之间有一个填充,我无法删除它(即使添加了padding: EdgeInsets.all(0.0))(如下图所示)。第二个问题是,我需要精确地点击图标才能出现菜单。 当单击index=2的BottomNavigationBarItem时,我尝试直接调用showMenu(PopupMenuButton调用的方法)。但很难确定菜单应从哪里出现。