In my Flutter app I have a screen that is a MaterialApp with a Scaffold widget as it's home.
The appBar property of this Scaffold is an AppBar widget with the actions property filled with some actions and a popup menu to house the rest of the options.
The thing is, as I understand a child of AppBar actions list can either be a generic widget (it will be added as an action) or an instance of PopupMenuButton, in which case it will add the platform specific icon that when triggered opens the AppBar popup menu.
On native Android that's not how it works. I just need to inflate a menu filled with menu items and each item either can be forced to be an action, forced to NOT be an action or have the special value "ifRoom" that means "be an action if there is space, otherwise be an item inside de popup menu".
Is there a way in Flutter to have this behavior without having to write a complex logic to populate the "actions" property of the AppBar?
I've looked into both AppBar and PopupMenuButton documentations and so far nothing explains how to do such a thing. I could simulate the behavior but then I would have to actually write a routine to calculate the available space and build the "actions" list accordingly.
Here's a typical Android menu that mixes actions and popup menu entries. Notice the "load_game" entry can be an action if there is room and will become a menu entry if not.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:icon="@drawable/ic_new_game"
android:title="@string/new_game"
android:showAsAction="always"/>
<item android:id="@+id/load_game"
android:icon="@drawable/ic_load_game"
android:title="@string/load_game"
android:showAsAction="ifRoom"/>
<item android:id="@+id/help"
android:icon="@drawable/ic_help"
android:title="@string/help"
android:showAsAction="never" />
</menu>
On the other hand in Flutter I have to decide ahead of time if the options will be an action or a menu entry.
AppBar(
title: Text("My Incredible Game"),
primary: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
tooltip: "New Game",
onPressed: null,
),
IconButton(
icon: Icon(Icons.cloud_upload),
tooltip: "Load Game",
onPressed: null,
),
PopupMenuButton(
itemBuilder: (BuildContext context) {
return <PopupMenuEntry>[
PopupMenuItem(
child: Text("Help"),
),
];
},
)
],
)
What I hoped would work is that the AppBar actually had just a single "action" property instead of "actions". That property would be just a widget allowing me to have anything so if I wanted just a list of actions then a Row filled with IconButton's would suffice.
Along with that each PopupMenuItem inside the PopupMenuButton would have a "showAsAction" property. If one or more PopupMenuItem inside the PopupMenuButton was checked to be an action or "ifRoom" and there is room, then the PopupMenuButton would expand horizontally and place these items as actions.

