I am trying to show a menu when a navigation bar item is clicked. This was my attempt:
@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()));
}
I encountered two problems. First one is the display of the NavigationBarItem. There is a padding between the icon
the title
that I could not remove (even by adding padding: EdgeInsets.all(0.0)
) (as the picture below shows). And the second is that I need to click exactly on the icon for the menu to appear.
I tried calling showMenu
directly (the method that PopupMenuButton
calls) when a BottomNavigationBarItem
of index=2
(for example) is clicked. But it was tricky how to determine the location of origin where the menu should appear from.