I have created a flutter list but how do I check if it is empty?
List<int> selectedItems = [];
However, selectedItems.isNotEmpty
gives me Conditions must have a static type of 'bool'.
error. How do I fix this?
I created a dropdown
SearchChoices.multiple(
clearIcon: const Icon(FontAwesomeIcons.times),
underline: Container(
color: const Color(0xffF0F0F0),
),
items:
_list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
selectedItems: selectedItems,
hint: const Padding(
padding: EdgeInsets.all(12.0),
child: Text("Select any"),
),
searchHint: "Select any",
onChanged: (value) {
setState(() {
value = selectedItems;
});
},
closeButton: (selectedItems) {
return selectedItems.isNotEmpty
? "Save ${selectedItems.length == 1 ? '"' + items[selectedItems.first].value.toString() + '"' : '(' + selectedItems.length.toString() + ')'}"
: "Save without selection";
},
isExpanded: true,
),
The error is here
closeButton: (selectedItems) {
return selectedItems.isNotEmpty
? "Save ${selectedItems.length == 1 ? '"' + items[selectedItems.first].value.toString() + '"' : '(' + selectedItems.length.toString() + ')'}"
: "Save without selection";
},
The dropdown package I used is: https://pub.dev/packages/searchable_dropdown
UPDATE
It seems that flutter sees the List<int>
as a dynamic
type. Ever since I began the project it has been assigning every variable as dynamic even if I specified its type. Screenshot of variable
Aucun commentaire:
Enregistrer un commentaire