不能将 'List<Object?> 的值类型分配给 'List<Looking Gender> 类型的变量
A value type of 'List<Object?> can't be assigned to a variable of type 'List<Looking Gender>
所以,我想做的是使用 multi_select_dropdown 允许约会应用程序的用户 select 多种事物,例如性别和取向,但我不断收到变量错误在主题中。这是我宣布名单的地方:
static List<LookingGender> _lookingGender = [
LookingGender(id: 1, name: 'Male'),
LookingGender(id: 2, name: 'Female'),
LookingGender(id: 3, name: 'TransMale'),
LookingGender(id: 4, name: 'TransFemale'),
LookingGender(id: 5, name: 'Non-Binary'),
LookingGender(id: 6, name: 'Agender'),
LookingGender(id: 7, name: 'Androgynous'),
LookingGender(id: 8, name: 'Genderfluid'),
LookingGender(id: 9, name: 'Genderqueer'),
LookingGender(id: 10, name: 'Intersex'),
LookingGender(id: 11, name: 'Two Spirit'),
];
final _selectedLookingGender = _lookingGender
.map((lookingGender) =>
MultiSelectItem<LookingGender>(lookingGender, lookingGender.name))
.toList();
List<LookingGender> _selectedLookingGender2 = [];
List<LookingGender> _selectedLookingGender3 = [];
List<LookingGender> _selectedLookingGender5 = [];
final _multiSelectKey = GlobalKey<FormFieldState>();
static List<LookingOrientation> _lookingOrientation = [
LookingOrientation(id: 1, name: 'Heterosexual'),
LookingOrientation(id: 2, name: 'Homosexual'),
LookingOrientation(id: 3, name: 'Lesbian'),
LookingOrientation(id: 4, name: 'Gay'),
LookingOrientation(id: 5, name: 'Demisexual'),
LookingOrientation(id: 6, name: 'Pansexual'),
LookingOrientation(id: 7, name: 'Asexual'),
LookingOrientation(id: 8, name: 'Bisexual'),
LookingOrientation(id: 9, name: 'Bicurious'),
];
final _selectedLookingOrientation = _lookingOrientation
.map((lookingOrientation) => MultiSelectItem<LookingOrientation>(
lookingOrientation, lookingOrientation.name))
.toList();
List<LookingOrientation> _selectedLookingOrientation2 = [];
List<LookingOrientation> _selectedLookingOrientation3 = [];
List<LookingOrientation> _selectedLookingOrientation5 = [];
这就是事情变得不稳定的地方。错误似乎在 'values' 变量上。
// Looking for Gender field
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor.withOpacity(0.4),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
),
),
child: Column(
children: <Widget>[
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
_selectedLookingGender2 = values;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),
_selectedLookingGender2 == null ||
_selectedLookingGender2.isEmpty
? Container(
padding: EdgeInsets.all(10),
alignment: Alignment.centerLeft,
child: const Text(
"None Selected",
style: TextStyle(color: Colors.black54),
))
: Container(),
],
),
),
SizedBox(height: 20),
MultiSelectChipField<LookingGender>(
items: _selectedLookingGender,
initialValue: [_lookingGender[1]],
title: const Text('Genders'),
headerColor: Colors.blue.withOpacity(0.5),
decoration: BoxDecoration(
border:
Border.all(color: (Colors.blue[700]!), width: 1.8),
),
selectedChipColor: Colors.blue.withOpacity(0.5),
selectedTextStyle: TextStyle(color: Colors.blue[800]),
onTap: (values) {},
),
const SizedBox(height: 20),
// Looking for Orientation field
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor.withOpacity(0.4),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
),
),
child: Column(
children: <Widget>[
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
_selectedLookingGender2 = values;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),
_selectedLookingGender2 == null ||
_selectedLookingGender2.isEmpty
? Container(
padding: EdgeInsets.all(10),
alignment: Alignment.centerLeft,
child: const Text(
"None Selected",
style: TextStyle(color: Colors.black54),
))
: Container(),
],
),
),
MultiSelectChipField(
items: _selectedLookingOrientation,
initialValue: [_lookingOrientation[1]],
title: const Text('Orientation'),
headerColor: Colors.blue.withOpacity(0.5),
decoration: BoxDecoration(
border:
Border.all(color: (Colors.blue[700]!), width: 1.8),
),
selectedChipColor: Colors.blue.withOpacity(0.5),
selectedTextStyle: TextStyle(color: Colors.blue[800]),
onTap: (values) {},
),
const SizedBox(height: 20),
我是这方面的新手,所以这是一段痛苦的旅程。
你可以试试这个:
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
List<LookingGender> tempSelectedLookingGender = [];
var newValues = values as List<MultiSelectItem<LookingGender>>;
newValues.forEach((element) {
tempSelectedLookingGender.add(element.value);
});
_selectedLookingGender2 = tempSelectedLookingGender;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),
所以,我想做的是使用 multi_select_dropdown 允许约会应用程序的用户 select 多种事物,例如性别和取向,但我不断收到变量错误在主题中。这是我宣布名单的地方:
static List<LookingGender> _lookingGender = [
LookingGender(id: 1, name: 'Male'),
LookingGender(id: 2, name: 'Female'),
LookingGender(id: 3, name: 'TransMale'),
LookingGender(id: 4, name: 'TransFemale'),
LookingGender(id: 5, name: 'Non-Binary'),
LookingGender(id: 6, name: 'Agender'),
LookingGender(id: 7, name: 'Androgynous'),
LookingGender(id: 8, name: 'Genderfluid'),
LookingGender(id: 9, name: 'Genderqueer'),
LookingGender(id: 10, name: 'Intersex'),
LookingGender(id: 11, name: 'Two Spirit'),
];
final _selectedLookingGender = _lookingGender
.map((lookingGender) =>
MultiSelectItem<LookingGender>(lookingGender, lookingGender.name))
.toList();
List<LookingGender> _selectedLookingGender2 = [];
List<LookingGender> _selectedLookingGender3 = [];
List<LookingGender> _selectedLookingGender5 = [];
final _multiSelectKey = GlobalKey<FormFieldState>();
static List<LookingOrientation> _lookingOrientation = [
LookingOrientation(id: 1, name: 'Heterosexual'),
LookingOrientation(id: 2, name: 'Homosexual'),
LookingOrientation(id: 3, name: 'Lesbian'),
LookingOrientation(id: 4, name: 'Gay'),
LookingOrientation(id: 5, name: 'Demisexual'),
LookingOrientation(id: 6, name: 'Pansexual'),
LookingOrientation(id: 7, name: 'Asexual'),
LookingOrientation(id: 8, name: 'Bisexual'),
LookingOrientation(id: 9, name: 'Bicurious'),
];
final _selectedLookingOrientation = _lookingOrientation
.map((lookingOrientation) => MultiSelectItem<LookingOrientation>(
lookingOrientation, lookingOrientation.name))
.toList();
List<LookingOrientation> _selectedLookingOrientation2 = [];
List<LookingOrientation> _selectedLookingOrientation3 = [];
List<LookingOrientation> _selectedLookingOrientation5 = [];
这就是事情变得不稳定的地方。错误似乎在 'values' 变量上。
// Looking for Gender field
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor.withOpacity(0.4),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
),
),
child: Column(
children: <Widget>[
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
_selectedLookingGender2 = values;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),
_selectedLookingGender2 == null ||
_selectedLookingGender2.isEmpty
? Container(
padding: EdgeInsets.all(10),
alignment: Alignment.centerLeft,
child: const Text(
"None Selected",
style: TextStyle(color: Colors.black54),
))
: Container(),
],
),
),
SizedBox(height: 20),
MultiSelectChipField<LookingGender>(
items: _selectedLookingGender,
initialValue: [_lookingGender[1]],
title: const Text('Genders'),
headerColor: Colors.blue.withOpacity(0.5),
decoration: BoxDecoration(
border:
Border.all(color: (Colors.blue[700]!), width: 1.8),
),
selectedChipColor: Colors.blue.withOpacity(0.5),
selectedTextStyle: TextStyle(color: Colors.blue[800]),
onTap: (values) {},
),
const SizedBox(height: 20),
// Looking for Orientation field
Container(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor.withOpacity(0.4),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
),
),
child: Column(
children: <Widget>[
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
_selectedLookingGender2 = values;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),
_selectedLookingGender2 == null ||
_selectedLookingGender2.isEmpty
? Container(
padding: EdgeInsets.all(10),
alignment: Alignment.centerLeft,
child: const Text(
"None Selected",
style: TextStyle(color: Colors.black54),
))
: Container(),
],
),
),
MultiSelectChipField(
items: _selectedLookingOrientation,
initialValue: [_lookingOrientation[1]],
title: const Text('Orientation'),
headerColor: Colors.blue.withOpacity(0.5),
decoration: BoxDecoration(
border:
Border.all(color: (Colors.blue[700]!), width: 1.8),
),
selectedChipColor: Colors.blue.withOpacity(0.5),
selectedTextStyle: TextStyle(color: Colors.blue[800]),
onTap: (values) {},
),
const SizedBox(height: 20),
我是这方面的新手,所以这是一段痛苦的旅程。
你可以试试这个:
MultiSelectBottomSheetField(
initialChildSize: 0.4,
listType: MultiSelectListType.CHIP,
searchable: true,
buttonText: Text('Looking for Gender'),
title: Text('Genders'),
items: _selectedLookingGender,
onConfirm: (values) {
List<LookingGender> tempSelectedLookingGender = [];
var newValues = values as List<MultiSelectItem<LookingGender>>;
newValues.forEach((element) {
tempSelectedLookingGender.add(element.value);
});
_selectedLookingGender2 = tempSelectedLookingGender;
},
chipDisplay: MultiSelectChipDisplay(
onTap: (value) {
setState(() {
_selectedLookingGender2.remove(value);
});
},
),
),