From 99dd7dbe19f2058d1eed01fef63614280847f3e8 Mon Sep 17 00:00:00 2001 From: niuhuan Date: Tue, 1 Mar 2022 20:00:27 +0800 Subject: [PATCH] fix select list value context --- lib/basic/Common.dart | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/basic/Common.dart b/lib/basic/Common.dart index e5cae2a..d46c442 100644 --- a/lib/basic/Common.dart +++ b/lib/basic/Common.dart @@ -97,26 +97,27 @@ List filteredList(List list, bool Function(T) filter) { Future chooseListDialog( BuildContext context, String title, List items, {String? tips}) async { - List widgets = []; - if (tips != null) { - widgets.add(Container( - padding: EdgeInsets.fromLTRB(15, 5, 15, 15), - child: Text(tips), - )); - } - widgets.addAll(items.map((e) => SimpleDialogOption( - onPressed: () { - Navigator.of(context).pop(e); - }, - child: Text('$e'), - ))); - return showDialog( context: context, builder: (BuildContext context) { return SimpleDialog( title: Text(title), - children: widgets, + children: [ + ...items.map((e) => SimpleDialogOption( + onPressed: () { + Navigator.of(context).pop(e); + }, + child: Text('$e'), + )), + ...tips != null + ? [ + Container( + padding: const EdgeInsets.fromLTRB(15, 5, 15, 15), + child: Text(tips), + ), + ] + : [], + ], ); }, );