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

时间:2019-01-22 20:46:27

标签: flutter flutter-layout

我正在尝试在ListTile下获得一个弹出菜单。 title显示说明,subtitle显示选择的值和一些消息,onTap打开弹出菜单,用户可以在其中选择一个值。

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

如何在ListTile上弹出菜单?

1 个答案:

答案 0 :(得分:1)

也许您可以尝试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'),
        ),
      ],
)

看看How to open a PopupMenuButton?