串列名稱 = [{"Label":"Name 1","Value":"60"},{"Label":"Name 2","Value":"61"},{"Label":"Name 3 ","值":"131"},{"標簽":"名稱 4","值":"62"},{"標簽":"名稱 5","值":"63"}];
我將字串更改為動態,它回傳:
“下拉選單項”
DropdownSearch<String>(
mode: Mode.BOTTOM_SHEET,
items: names.map((item) {
return DropdownMenuItem(
child: new Text(item['Label'].toString()),
value: item['Value'].toString(),
);
}).toList(),
dropdownSearchDecoration: InputDecoration(
labelText: "Custom BottomShet mode",
contentPadding: EdgeInsets.fromLTRB(12, 12, 0, 0),
border: OutlineInputBorder(),
),
onChanged: print,
showSearchBox: true,
searchFieldProps: TextFieldProps(
decoration: InputDecoration(
border: OutlineInputBorder(),
contentPadding: EdgeInsets.fromLTRB(12, 12, 8, 0),
labelText: "Select...",
),
),
popupTitle: Container(
height: 50,
decoration: BoxDecoration(
color: Theme.of(context).primaryColorDark,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Center(
child: Text(
'Search',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
popupShape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
),
),
),
uj5u.com熱心網友回復:
另一種方法是使用List.generate函式:
DropdownSearch<String>(
mode: Mode.BOTTOM_SHEET,
items: List<String>.generate(
names.length,
(index) {
return names[index]['Value'].toString();
},
growable: false,
),
...
uj5u.com熱心網友回復:
items不是DropdownMenuItem型別String。
DropdownSearch<DropdownMenuItem>(
mode: Mode.BOTTOM_SHEET,
items: names.map((item) {
return DropdownMenuItem(
child: new Text(item['Label'].toString()),
value: item['Value'].toString(),
);
}).toList(),
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/469462.html
