我有以下代码将一堆复选框放在 dropDownMenu 中 此代码在空安全之前运行良好,但现在显示一些错误
ActivityType dropdownValue = ActivityType(activityTypeName: "hell", id: 1);
List<ActivityType> activityList = [
ActivityType(activityTypeName: "hell", id: 1),
ActivityType(activityTypeName: "para", id: 2)
];
List<ActivityType> selectedCheckBoxItems1 = [];
DropdownButtonHideUnderline(
child: DropdownButton(
value: dropdownValue,
onChanged: (dynamic val) {},
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
items: activityList
.map((e) => DropdownMenuItem(
child: Container(
width: MediaQuery.of(context).size.width / 2,
child: StatefulBuilder(
builder:
(BuildContext context, StateSetter setState) {
return CheckboxListTile(
title: Text(e.activityTypeName ?? ""),
value: selectedCheckBoxItems1.indexWhere(
(element) =>
element.activityTypeName ==
e.activityTypeName) >=
0
? true
: false,
onChanged: (value) {
setSelectedCheckBox1(e, value!);
setState(() {});
});
},
),
)))
.toList(),
))
<块引用>
<块引用>
以下断言被抛出构建 testDrop(dirty, dependencies: [MediaQuery], state: _testDropState#146a8): There should 恰好是具有 [DropdownButton] 值的一项:Instance of '活动类型'。零个或 2 个或更多 [DropdownMenuItem] 是 检测到相同的值 'package:flutter/src/material/dropdown.dart':失败的断言:行 850 pos 15: 'items == null || items.isEmpty ||值 == 空 || items.where((DropdownMenuItem item) { 返回 item.value == 值; }).length == 1'