Dn-a / flutter_tags

With flutter tags you can create selectable or input tags that automatically adapt to the screen width

Home Page:https://pub.dartlang.org/packages/flutter_tags

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Single item mode is not working properly with horizontal scroll

afominov opened this issue Β· comments

Selecting tag item causes an exception in case Tags widget builds with horizontalScroll: true and ItemTags - with singleItem: true.

I'm very new in flutter, but I've made a small investigation.
It looks like, that in case horizontal scrolling with no symmetry the default ListView widget is used for building tag items list. If singleItem mode is true, selecting of tag item causes an exception, because of not all ListView items was builded and we are not be able to "disativate" each item in ItemTagsState._singleItem()

As I said, I'm new with flutter. I think, I get a reason of that bug (hope I get it right πŸ˜„ ), but I have no idea how to fix it in a proper way.

Steps to reproduce:

  1. run example app
  2. enable horizontal scroll and single item checkboxes
  3. switch to "Demo 2" tab and move back to "Demo 1"
  4. try to select tag item with pre-selected options in step two

Stack trace:

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The getter 'active' was called on null.
Receiver: null
Tried calling: active

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      _ItemTagsState._singleItem.<anonymous closure> (package:flutter_tags/src/item_tags.dart:442:27)
#2      WhereIterator.moveNext (dart:_internal/iterable.dart:442:13)
#3      WhereIterator.moveNext (dart:_internal/iterable.dart:441:22)
#4      Iterable.forEach (dart:core/iterable.dart:283:23)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#e7b35
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(203.6, 240.7)
  finalLocalPosition: Offset(66.6, 26.0)
  button: 1
  sent tap down
════════════════════════════════════════════════════════════════════════════════════════════════════

hi @omnifer, could you post your code? you must also indicate the version with flutter doctor

Hi, @Dn-a
I've made a sample app and pushed code here, you can clone and run it.

Also the bug exists in example app from this repository. You can reproduce it with steps I wrote above.

flutter doctor -v

[βœ“] Flutter (Channel stable, 1.22.3, on Linux, locale en_US.UTF-8)
    β€’ Flutter version 1.22.3 
    β€’ Framework revision 8874f21e79 (13 days ago), 2020-10-29 14:14:35 -0700
    β€’ Engine revision a1440ca392
    β€’ Dart version 2.10.3

[βœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    β€’ Android SDK at /home/alexander/Android/Sdk
    β€’ Platform android-30, build-tools 30.0.2
    β€’ Java binary at: /usr/bin/java
    β€’ Java version OpenJDK Runtime Environment 18.9 (build 11.0.9+11)
    β€’ All Android licenses accepted.

@omnifer yes it's a bug and I will fix it in the next release.
thanks.