'flutter_tags giving error when clicking Enter

I am using flutter_tags package in my project. when i add text in the TagsTextField and press Enter I get below error and that part becomes red.

Expected a value of type 'DataList', but got one of type 'Null'

Code:


List subs = [];

final GlobalKey<TagsState> _globalKey = GlobalKey<TagsState>();

// Rest of the code


Tags(
                key: _globalKey,
                itemCount: subs.length,
                columns: 6,
                textField: TagsTextField(
                    textStyle: const TextStyle(fontSize: 14),
                    onSubmitted: (String str) {
                      setState(() {
                        subs.add(
                          Item(title: str),
                        );
                        showDialogBox(context, "showing", subs.toString());
                      });
                    }),
                itemBuilder: (i) {
                  final currentItem = subs[i]!;
                  print(currentItem);
                  return ItemTags(
                    index: i,
                    title: currentItem.title,
                    customData: currentItem.customData,
                    onPressed: (curr) => print(curr),
                    onLongPressed: (curr) => print(curr),
                    removeButton: ItemTagsRemoveButton(
                      onRemoved: () {
                        setState(() {
                          subs.removeAt(i);
                        });
                        return true;
                      },
                    ),
                  );
                },
              )


// rest of the code

*Before Clicking Enter

enter image description here

After I Click Enter

enter image description here



Solution 1:[1]

remove this line

 customData: currentItem.customData,

and it will work.

Solution 2:[2]

Edit: Updated my comment.

  1. title: currentItem.title <- the types do not match, one is String and the other is String? You need to read the documentation on how to handle/use null safety in dart.

https://dart.dev/null-safety/understanding-null-safety

  1. Could also be due to your list not being initialized properly. Try the below:

List subs= List.empty(growable: true);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bayhas
Solution 2