hiddencaliber / flutter_multiselect

Flutter package for multi-select UI widget
Other
52 stars 37 forks source link

Error. Bad state: Too many elements #5

Closed KMantas closed 5 years ago

KMantas commented 5 years ago

I've tried using example in readme and while select items I get this error, it is quite random - sometimes it throws error on first checkbox click sometimes on 2nd or 3rd. Here is what I got:

I/flutter (19741): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (19741): The following StateError was thrown building SelectionModal(dirty, state: I/flutter (19741): _SelectionModalState#19b72): I/flutter (19741): Bad state: Too many elements I/flutter (19741): I/flutter (19741): When the exception was thrown, this was the stack: I/flutter (19741): #0 _ListBase&Object&ListMixin.singleWhere (dart:collection/list.dart:172:11) I/flutter (19741): #1 _SelectionModalState._currentlySelectedOptions.<anonymous closure> (package:flutter_multiselect/selection_modal.dart:154:12) I/flutter (19741): #2 List.forEach (dart:core/runtime/libgrowable_array.dart:278:8) I/flutter (19741): #3 _SelectionModalState._currentlySelectedOptions (package:flutter_multiselect/selection_modal.dart:152:20) I/flutter (19741): #4 _SelectionModalState._buildBody (package:flutter_multiselect/selection_modal.dart:93:11) I/flutter (19741): #5 _SelectionModalState.build (package:flutter_multiselect/selection_modal.dart:256:13) I/flutter (19741): #6 StatefulElement.build (package:flutter/src/widgets/framework.dart:3825:27) I/flutter (19741): #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3736:15) I/flutter (19741): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:3559:5) I/flutter (19741): #9 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2273:33) I/flutter (19741): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:700:20) I/flutter (19741): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:268:5) I/flutter (19741): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:988:15) I/flutter (19741): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:928:9) I/flutter (19741): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:840:5)

solution I found is to replace singleWhere with firstWhere in both places it is used in code. Then it works fine.

hiddencaliber commented 5 years ago

@KMantas Thanks for reporting this issue.

Please verify your dataSource if you have duplicate objects

One thing to note here - firstWhere() returns the first match in the list, while singleWhere() returns the first match provided there is exactly one match.

I just tested this, works fine for me.

Thanks,

hiddencaliber commented 5 years ago

@KMantas I am closing this one. Please let me know if this is still an issue. You can always reopen or create a new one.