How to make PopupMenuItems change according to Tabs in TabBar like WhatsApp

240 Views Asked by At

How do I make PopupMenuItem change according to the change of tabs in the TabBar ? Like WhatsApp.

1

There are 1 best solutions below

0
On

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 [];
        }),
],