【发布时间】:2021-03-21 19:36:51
【问题描述】:
我想在 _menuItems 的第 0 个索引处设置自定义值。
这是我到目前为止所做的:
int _value;
List<custom.DropdownMenuItem<int>> _menuItems;
initDropdown() {
dynamic data = Provider.of<RestApiData>(context, listen: false).data;
List dataList = data[1]["offers"];
_menuItems = List<custom.DropdownMenuItem<int>>(dataList.length+1);
_menuItems[0] = custom.DropdownMenuItem(
value: -1,
child: Text(
'allOffers'.tr().toString(),
style: GoogleFonts.ubuntu(fontWeight: FontWeight.w500, fontSize: 14.0),
),
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.black54, width: 0.5))),
);
for (int i = 1; i <= _menuItems.length; i++) {
_menuItems[i] = custom.DropdownMenuItem(
value: int.parse(dataList[i]["Offer"]["id"]),
child: Text(
"${dataList[i]["Offer"]["name"]}",
style:
GoogleFonts.ubuntu(fontWeight: FontWeight.w500, fontSize: 14.0),
),
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.black54, width: 0.5))),
);
}
}
@override
void initState() {
super.initState();
initDropdown();
}
我已经尝试过这种方式,但得到 RangeError。 任何帮助将不胜感激。 提前致谢。
【问题讨论】: