How to open a PopupMenuButton?

后端 未结 6 1748
暗喜
暗喜 2021-01-07 17:34

How do I open a popup menu from a second widget?

final button = new PopupMenuButton(
    itemBuilder: (_) => >[
                 


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 18:11

    I found a solution to your question. You can provide a child to PopupMenuButton which can be any Widget including a ListTile (see code below). Only problem is that the PopupMenu opens on the left side of the ListTile.

    final popupMenu = new PopupMenuButton(
      child: new ListTile(
        title: new Text('Doge or lion?'),
        trailing: const Icon(Icons.more_vert),
      ),
      itemBuilder: (_) => >[
                new PopupMenuItem(
                    child: new Text('Doge'), value: 'Doge'),
                new PopupMenuItem(
                    child: new Text('Lion'), value: 'Lion'),
              ],
      onSelected: _doSomething,
    )
    

提交回复
热议问题