简体   繁体   中英

Flutter how to get a popup menu on a ListTile?

I'm trying to get a popupmenu under a ListTile . The title displays a description, the subtitle displays the selected value with some message and the onTap opens the popupmenu in which a user can select a value.

I tried putting a DropdownButtonHideUnderline in the subtitle , but this displays an arrow and does not respond to the ListTile onTab obviously.

How can I get a popupmenu on a ListTile ?

Maybe you can try PopuMenuButton,

PopupMenuButton<String>(
    onSelected: (String value) {
    setState(() {
        _selection = value;
    });
  },
  child: ListTile(
    leading: IconButton(
      icon: Icon(Icons.add_alarm),
      onPressed: () {
        print('Hello world');
      },
    ),
    title: Text('Title'),
    subtitle: Column(
      children: <Widget>[
        Text('Sub title'),
        Text(_selection == null ? 'Nothing selected yet' : _selection.toString()),
      ],
    ),
    trailing: Icon(Icons.account_circle),
  ),
  itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
        const PopupMenuItem<String>(
          value: 'Value1',
          child: Text('Choose value 1'),
        ),
        const PopupMenuItem<String>(
          value: 'Value2',
          child: Text('Choose value 2'),
        ),
        const PopupMenuItem<String>(
          value: 'Value3',
          child: Text('Choose value 3'),
        ),
      ],
)

Take a look at How to open a PopupMenuButton?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM