Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to add 3 dot pop up menu AppBar in Flutter

Tags:

flutter

dart

  1. I want a 3 dot popup menu button in the app bar of my app

  2. It must be a clickable one [navigate to other widgets,pages]

  3. Please tell how to add a pop up menu button in a simpler way

like image 907
abin Avatar asked Sep 28 '19 09:09

abin


People also ask

How do I show the popup menu in Flutter?

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.

How do I add buttons to AppBar Flutter?

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.


1 Answers

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;     } } 
like image 168
Ondřej Trojan Avatar answered Sep 20 '22 02:09

Ondřej Trojan