0

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

1 Answers1

-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