简体   繁体   English

Flutter如何在ListTile上获取弹出菜单?

[英]Flutter how to get a popup menu on a ListTile?

I'm trying to get a popupmenu under a ListTile . 我正在尝试在ListTile下获得一个popupmenu。 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. title显示说明, subtitle显示带有某些消息的所选值, onTap打开弹出菜单,用户可以在其中选择一个值。

I tried putting a DropdownButtonHideUnderline in the subtitle , but this displays an arrow and does not respond to the ListTile onTab obviously. 我尝试将DropdownButtonHideUnderline放在subtitle ,但这会显示箭头,并且显然不会响应ListTile onTab

How can I get a popupmenu on a ListTile ? 如何在ListTile上获得ListTile

Maybe you can try PopuMenuButton, 也许您可以尝试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? 看看如何打开PopupMenuButton?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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