我试图使菜单保持打开状态,以便我可以一次选择多个类别,而不必在每次选择后都返回到页面。
如果它可以像Excel过滤器数据(或Libreoffice Autofilter)一样工作,那就太完美了
添加了屏幕截图
任何想法将不胜感激!
代码:
import 'package:flutter/material.dart';
void main() { return runApp(MaterialApp(
home: MenuDemo(), )); }
class MenuDemo extends StatefulWidget { const MenuDemo({Key key}) : super(key: key);
static const String routeName = '/material/menu';
@override MenuDemoState createState() => new MenuDemoState(); }
class MenuDemoState extends State<MenuDemo> { final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
final String _checkedValue1 = 'One'; final String _checkedValue2 = 'Two'; final String _checkedValue3 = 'Free'; final String
_checkedValue4 = 'Four'; List<String> _checkedValues;
@override void initState() {
super.initState();
_checkedValues = <String>[_checkedValue3]; }
void showInSnackBar(String value) {
_scaffoldKey.currentState
.showSnackBar(new SnackBar(content: new Text(value))); }
void showCheckedMenuSelections(String value) {
if (_checkedValues.contains(value))
_checkedValues.remove(value);
else
_checkedValues.add(value);
showInSnackBar('Checked $_checkedValues'); }
bool isChecked(String value) => _checkedValues.contains(value);
@override Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
body: Center(
child: Container(
width: 250.0,
child: new ListTile(
title: const Text(
'checklist menu',
textAlign: TextAlign.center,
),
trailing: new PopupMenuButton<String>(
padding: EdgeInsets.zero,
onSelected: showCheckedMenuSelections,
itemBuilder: (BuildContext context) =>
<PopupMenuItem<String>>[
new CheckedPopupMenuItem<String>(
value: _checkedValue1,
checked: isChecked(_checkedValue1),
child: new Text(_checkedValue1)),
new CheckedPopupMenuItem<String>(
value: _checkedValue2,
//enabled: false,
checked: isChecked(_checkedValue2),
child: new Text(_checkedValue2)),
new CheckedPopupMenuItem<String>(
value: _checkedValue3,
checked: isChecked(_checkedValue3),
child: new Text(_checkedValue3)),
new CheckedPopupMenuItem<String>(
value: _checkedValue4,
checked: isChecked(_checkedValue4),
child: new Text(_checkedValue4))
])),
),
)); } }