Home > OS >  type '(List<String>) => Null' is not a subtype of type '((List<String?>
type '(List<String>) => Null' is not a subtype of type '((List<String?>

Time:01-29

I used multi_select_flutter and I got errors. I do not know what I am missing. Below is my code.

                List<String>? sectionIds = [];
                final _items = sections
                 .map(
                     (section) => MultiSelectItem<String>(
                      section,
                      section.toUpperCase(),
                  ),
                )
               .toList();
                MultiSelectChipField(
                  items: _items,
                  initialValue: sectionIds,
                  title: const Text("Section"),
                  headerColor: Colors.blue.withOpacity(0.5),
                  decoration: BoxDecoration(
                    border: Border.all(
                        color: const Color(0xFF059CD1), width: 1.8),
                  ),
                  selectedChipColor: Colors.blue.withOpacity(0.5),
                  selectedTextStyle: TextStyle(color: Colors.blue[800]),
                  onTap: (List<String> values) {
                    sectionIds = values;
                    //_selectedAnimals4 = values;
                  },
                ),

Error occurred: type '(List) => Null' is not a subtype of type '((List<String?>) => dynamic)?' Please why did this error occur?

CodePudding user response:

you just need to change List<String> values to List<String?> values:

                List<String>? sectionIds = [];
                final _items = sections
                 .map(
                     (section) => MultiSelectItem<String>(
                      section,
                      section.toUpperCase(),
                  ),
                )
               .toList();
                MultiSelectChipField(
                  items: _items,
                  initialValue: sectionIds,
                  title: const Text("Section"),
                  headerColor: Colors.blue.withOpacity(0.5),
                  decoration: BoxDecoration(
                    border: Border.all(
                        color: const Color(0xFF059CD1), width: 1.8),
                  ),
                  selectedChipColor: Colors.blue.withOpacity(0.5),
                  selectedTextStyle: TextStyle(color: Colors.blue[800]),
                  onTap: (List<String?> values) {
                    sectionIds = values;
                    //_selectedAnimals4 = values;
                  },
                ),
  •  Tags:  
  • Related