How do I make PopupMenuItem change according to the change of tabs in the TabBar ? Like WhatsApp.
Asked
Active
Viewed 158 times
0
-
Can you include your code snippet? You can check current tab and based on that populate the PopUpMenu. – Md. Yeasin Sheikh Sep 22 '21 at 17:43
-
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 01 '21 at 19:22
1 Answers
-1
include appbar actions:
actions: [
IconButton(
onPressed: () {},
icon: Icon(Icons.camera_alt_outlined)),
IconButton(onPressed: () {}, icon: Icon(Icons.search)),
PopupMenuButton(
// add icon, by default "3 dot" icon
// icon: Icon(Icons.book)
itemBuilder: (context) {
var mypop = DefaultTabController.of(context) !.index;
if (mypop == 0) {
return [
PopupMenuItem < int > (
padding: EdgeInsets.only(left: 10, right: 50),
height: 30,
child: Text("Settings"),
),
];
} else if (mypop == 1) {
return [
PopupMenuItem < int > (
child: Text("New group"),
),
PopupMenuItem < int > (
child: Text("New broadcast"),
),
PopupMenuItem < int > (
child: Text("Starred messages"),
),
PopupMenuItem < int > (
child: Text("Payments"),
),
PopupMenuItem < int > (
child: Text("Settings"),
),
];
} else if (mypop == 2) {
return [
PopupMenuItem < int > (
child: Text("Status privacy"),
),
PopupMenuItem < int > (
child: Text("Settings"),
),
];
} else if (mypop == 3) {
return [
PopupMenuItem < int > (
child: Text("Clear call log"),
),
PopupMenuItem < int > (
child: Text("Settings"),
),
];
}
return [];
}),
],

Vivek Gupta
- 2,534
- 3
- 15
- 28

Sathar T
- 1
- 1