I want a 3 dot popup menu button in the app bar of my app
It must be a clickable one [navigate to other widgets,pages]
Please tell how to add a pop up menu button in a simpler way
Displays a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. If we focus on an Application, We can see in every Application there is a Pop Up Menu button that will do some work.
Flutter allow you to create menu or leading button in Appbar. Usually we create menu button manually in android but in flutter we create menu or leading button using a single Appbar properties. Just add below code in your Appbar widget to create customize leading button. It is located on the left side of the Appbar.
The simplistic way is undoubtedly to avoid auxiliary classes. As of Dart 2.2 with the use of set literals, we can place the map of menu items in the app bar directly
appBar: AppBar( title: Text('Homepage'), actions: <Widget>[ PopupMenuButton<String>( onSelected: handleClick, itemBuilder: (BuildContext context) { return {'Logout', 'Settings'}.map((String choice) { return PopupMenuItem<String>( value: choice, child: Text(choice), ); }).toList(); }, ), ], ),
and handle click with value of Item text in method
void handleClick(String value) { switch (value) { case 'Logout': break; case 'Settings': break; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With