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

Single item mode is not working properly with horizontal scroll #66

Closed afominov closed 4 years ago

afominov commented 4 years ago

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 :smile: ), 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
════════════════════════════════════════════════════════════════════════════════════════════════════
Dn-a commented 4 years ago

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

afominov commented 4 years ago

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.
Dn-a commented 4 years ago

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

Dn-a commented 4 years ago

new release 0.4.9+1