我正在尝试在ListTile下获取一个popupmenu。 title显示描述,subtitle显示带有某些消息的所选值,并且onTap打开弹出菜单,用户可以在其中选择一个值。

我尝试将DropdownButtonHideUnderline放入subtitle中,但这会显示一个箭头,并且显然不会响应ListTile onTab

我如何在ListTile上获得弹出菜单?

最佳答案

也许您可以尝试PopupMenuButton,

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'),
        ),
      ],
)
看看How to open a PopupMenuButton?

关于Flutter如何在ListTile上获取弹出菜单?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54316193/

10-10 20:02