如何在多选模式下更改 Flutter 中显示 dropdown_search 包的弹出窗口的“确定”按钮的文本。
DropdownSearch<String>.multiSelection(
popupProps: PopupPropsMultiSelection.menu(
showSearchBox: false,
showSelectedItems: false,
fit: FlexFit.loose,
),
)
软件包:https://pub.dev/packages/dropdown_search
我在文档中没有找到任何更改此文本的方法。
您无法修改该按钮上的实际文本,但可以修改按钮创建。
这就是按钮的创建方式:源代码
您可以提供类似的方法作为
validationBuilder
参数给您popupProps
。像这样:
DropdownSearch<String>.multiSelection(
popupProps: PopupPropsMultiSelection.menu(
showSearchBox: false,
showSelectedItems: false,
fit: FlexFit.loose,
validationBuilder: (context, items) => Padding(
padding: EdgeInsets.all(8),
child: Align(
alignment: Alignment.centerRight,
child: ElevatedButton(
onPressed: () {
// do something here with items
// Also you can close dialog here with
// Navigator.pop(context);
// default implementation does 2 things:
// 1. calls onChanged method with items as parameter
// 2. Closes popup with Navigator.pop(context);
},
child: Text("Your text"),
),
),
),
),
);
注意
onPressed
– 您必须提供关闭此菜单并操作所选项目的实际逻辑。我留下了带有建议和或多或少默认实现的评论。