Dn-a / flutter_tags

With flutter tags you can create selectable or input tags that automatically adapt to the screen width
https://pub.dartlang.org/packages/flutter_tags
MIT License
508 stars 124 forks source link

type 'Null' is not a subtype of type 'DataList' in type cast #79

Open sarbogast opened 3 years ago

sarbogast commented 3 years ago

I'm trying to integrate this library into my project and I want to let users choose items from a list or add their own items to it. Here is what I have so far:

final GlobalKey<TagsState> _tagStateKey = GlobalKey<TagsState>();
  List<String> _existingTopics = ['religion', 'politics', 'literature'];
  List<String> _topics = [];

...
Tags(
                  key: _tagStateKey,
                  textField: TagsTextField(
                    constraintSuggestion: true,
                    suggestions: _existingTopics,
                    //width: double.infinity, padding: EdgeInsets.symmetric(horizontal: 10),
                    onSubmitted: (String str) {
                      // Add item to the data source.
                      setState(() {
                        // required
                        _topics.add(str);
                      });
                    },
                  ),
                  itemCount: _topics.length, // required
                  itemBuilder: (int index) {
                    final topic = _topics[index];

                    return ItemTags(
                      // Each ItemTags must contain a Key. Keys allow Flutter to
                      // uniquely identify widgets.
                      key: Key(index.toString()),
                      index: index, // required
                      title: topic,
                      combine: ItemTagsCombine.withTextBefore,
                      image: null,
                      icon: null,
                      removeButton: ItemTagsRemoveButton(
                        onRemoved: () {
                          // Remove the item from the data source.
                          setState(() {
                            _topics.removeAt(index);
                          });
                          return true;
                        },
                      ),
                    );
                  },
                )

But when I start typing one of the _existingTopics and then type the submit button on the iOS keyboard, I see this:

Capture d’écran 2021-04-08 à 00 16 26

And I get the following exception:

[+165250 ms] flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
[   +2 ms] flutter: The following _CastError was thrown building ItemTags-[<'0'>](dirty, dependencies:
[        ] flutter: [DataListInherited], state: _ItemTagsState#81225):
[        ] flutter: type 'Null' is not a subtype of type 'DataList' in type cast
[        ] flutter:
[        ] flutter: The relevant error-causing widget was:
[   +8 ms] flutter:   ItemTags-[<'0'>] file:///Users/sarbogast/dev/blindly/blindly/lib/screens/topics_screen.dart:108:28
[        ] flutter:
[        ] flutter: When the exception was thrown, this was the stack:
[        ] flutter: #0      List.length= (dart:core-patch/growable_array.dart:222:12)
[        ] flutter: #1      _ItemTagsState._setDataList (package:flutter_tags/src/item_tags.dart:153:33)
[        ] flutter: #2      _ItemTagsState.build (package:flutter_tags/src/item_tags.dart:214:5)
[        ] flutter: #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27)
[        ] flutter: #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)
[        ] flutter: #5      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #6      Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4474:5)
[        ] flutter: #8      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4658:11)
[        ] flutter: #9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5)
[        ] flutter: #10     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
[        ] flutter: #11     Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18)
[        ] flutter: #12     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5561:32)
[        ] flutter: #13     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6105:17)
[        ] flutter: #14     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #15     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[  +16 ms] flutter: #16     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #17     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #18     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #20     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #21     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #22     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #23     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #25     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #26     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #27     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #28     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5503:32)
[        ] flutter: #29     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6105:17)
[        ] flutter: #30     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #31     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5981:14)
[        ] flutter: #32     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #34     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #35     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #36     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #37     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5981:14)
[        ] flutter: #38     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #39     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #40     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #41     StatelessElement.update (package:flutter/src/widgets/framework.dart:4576:5)
[        ] flutter: #42     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #43     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #44     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #45     StatelessElement.update (package:flutter/src/widgets/framework.dart:4576:5)
[        ] flutter: #46     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #48     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #49     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #50     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #51     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #52     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #53     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #54     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #55     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5503:32)
[        ] flutter: #56     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6105:17)
[        ] flutter: #57     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #58     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #59     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #60     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #61     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #62     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #64     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #65     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[  +17 ms] flutter: #66     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #67     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #68     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #69     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #70     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #71     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #72     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5981:14)
[        ] flutter: #73     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #74     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #75     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #76     StatelessElement.update (package:flutter/src/widgets/framework.dart:4576:5)
[        ] flutter: #77     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #78     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5981:14)
[        ] flutter: #79     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #80     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #81     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #82     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #83     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #84     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #85     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #86     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #87     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #88     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #89     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #90     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #91     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #92     ProxyElement.update (package:flutter/src/widgets/framework.dart:4843:5)
[        ] flutter: #93     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #94     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #95     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #96     Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #97     StatefulElement.update (package:flutter/src/widgets/framework.dart:4699:5)
[        ] flutter: #98     Element.updateChild (package:flutter/src/widgets/framework.dart:3293:15)
[        ] flutter: #99     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4520:16)
[        ] flutter: #100    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4667:11)
[        ] flutter: #101    Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
[        ] flutter: #102    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2694:33)
[        ] flutter: #103    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:873:21)
[        ] flutter: #104    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
[        ] flutter: #105    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
[        ] flutter: #106    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
[        ] flutter: #107    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:998:5)
[        ] flutter: #111    _invoke (dart:ui/hooks.dart:161:10)
[        ] flutter: #112    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:253:5)
[        ] flutter: #113    _drawFrame (dart:ui/hooks.dart:120:31)
[        ] flutter: (elided 3 frames from dart:async)

And the component crashes. Did I forget something?

Note that I am using Flutter 2.0.5 with null safety, along with version 1.0.0-nullsafety.1 of the flutter_tags library

zhoupenglei commented 3 years ago

type 'Null' is not a subtype of type 'DataList' in type cast

item_tags.dart 151 line // set List length if (_dataListInherited!.list!.length < _dataListInherited!.itemCount!) _dataListInherited!.list!.length = _dataListInherited!.itemCount!;

SeriousMonk commented 3 years ago

I am also getting the same error. It worked just fine before migrating to null safety. The error is thrown for each ItemTags element built. If the list is empty no error is thrown.

FlagshipApps commented 3 years ago

Same here

topilski commented 3 years ago

Same

davidp918 commented 3 years ago

Same

48miles commented 3 years ago

remove

if (_dataListInherited!.list!.length < _dataListInherited!.itemCount!) _dataListInherited!.list!.length = _dataListInherited!.itemCount!;

and rerun your app. it worked for me.

mrruby commented 3 years ago

Any news about that?

oddmentiusmaximus commented 3 years ago

if (_dataListInherited!.list!.length < _dataListInherited!.itemCount!) _dataListInherited!.list!.length = _dataListInherited!.itemCount!; commenting this out worked , can we update this

BachirBichri commented 3 years ago

Any news on this?

xarmatura commented 3 years ago

@sarbogast @Dn-a Same, it showstopper, could you please check?

84 Merge maybe or give me an answer, please

Update Flutter has already a native widget Chip or ActionChip

hoctrinh commented 3 years ago

Pls fix it. Thanks.

bapm91 commented 3 years ago

commented this don't worked for me.

if (_dataListInherited!.list!.length < _dataListInherited!.itemCount!)
_dataListInherited!.list!.length = _dataListInherited!.itemCount!;

I changed final List<DataList> _list = []; to final List<DataList?> _list = []; and correct the errors that follow from here It's worked

szuwest commented 2 years ago

same here

rengert commented 2 years ago

same here, would be great to get an update

tony123S commented 2 years ago

same!