DavideBelsole / great_list_view

pub.dev library for flutter
MIT License
41 stars 22 forks source link

Exception on dispose after animation using Flutter 3.7.0 #25

Closed redarflap closed 1 year ago

redarflap commented 1 year ago

Hi, i keep getting various exceptions when modifying the list. The following exception throws on dispose, after adding an item to the list, after the animation is complete. Update: The issue seems to be related to Flutter 3.7.0

_AssertionError ('package:flutter/src/foundation/change_notifier.dart': Failed assertion: line 325 pos 7: '_notificationCallStackDepth == 0': The "dispose()" method on attachedTo: {}, time: 1.0, value: 1.0 DISPOSED was called during the call to "notifyListeners()". This is likely to cause errors since it modifies the list of listeners while the list is being used.)

Code snippet:

final animatedListControllerProvider =
    Provider.autoDispose<AnimatedListController>(
        (ref) => AnimatedListController());

class GreatListViewContent extends ConsumerWidget {
  const GreatListViewContent({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final state = ref.watch(listNotifierProvider);
    final listController = ref.watch(animatedListControllerProvider);

    return AutomaticAnimatedListView<int>(
      physics: const NeverScrollableScrollPhysics(),
      list: state.list,
      comparator: AnimatedListDiffListComparator<int>(
          sameItem: (a, b) => a == b, sameContent: (a, b) => a == b),
      itemBuilder: (context, item, data) =>
          Card(child: ListTile(title: Text(item.toString()))),
      listController: listController,
      detectMoves: true,
      shrinkWrap: true,
    );
  }
}

Stack:


_AssertionError._throwNew (dart:core-patch/errors_patch.dart:40)
ChangeNotifier.dispose (c:\Users\Joi\fvm\versions\3.7.0\packages\flutter\lib\src\foundation\change_notifier.dart:325)
_ControlledAnimation.dispose (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\animation.dart:112)
_ControlledAnimation.detachFrom (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\animation.dart:102)
_AnimatedSpaceInterval.dispose (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\intervals.dart:539)
_IntervalList.replace.<anonymous closure> (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\interval_list.dart:143)
Iterable.forEach (dart:core/iterable.dart:325)
_IntervalList.replace (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\interval_list.dart:141)
_IntervalManager.onIntervalCompleted (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\interval_manager.dart:852)
_IntervalManager._createAnimation.<anonymous closure>.<anonymous closure> (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\interval_manager.dart:926)
List.forEach (dart:core-patch/growable_array.dart:416)
_IntervalManager._createAnimation.<anonymous closure> (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\interval_manager.dart:924)
ChangeNotifier.notifyListeners (c:\Users\Joi\fvm\versions\3.7.0\packages\flutter\lib\src\foundation\change_notifier.dart:381)
_ControlledAnimation._onCompleted (c:\Users\Joi\AppData\Local\Pub\Cache\hosted\pub.dev\great_list_view-0.2.0+2\lib\src\animation.dart:139)
_RootZone.run (dart:async/zone.dart:1654)
_FutureListener.handleWhenComplete (dart:async/future_impl.dart:190)
Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:737)
Future._propagateToListeners (dart:async/future_impl.dart:793)
Future._completeWithValue (dart:async/future_impl.dart:567)```
JasCodes commented 1 year ago

@redarflap Are you on flutter 3.7.0? I was also planing to submit issue regarding this. As temporary fix you can try using last stable version of flutter to double check. For using multiple versions of flutter use https://fvm.app

JasCodes commented 1 year ago

@redarflap Oh i see you are already using fvm, and your version is indeed 3.7.0 try using 3.3.10

redarflap commented 1 year ago

@redarflap Oh i see you are already using fvm, and your version is indeed 3.7.0 try using 3.3.10

You were right, after going back to 3.3.7 (i had that one laying around) it works.

I still have an unrelated issue however. While adding, and reordering works, removing items from the list doesn't clear them from the UI. I guess that might be due to my Widget not being stateful? In the examples it's always a stateful widget with global key being assigned.

Caeruleo commented 1 year ago

I'm getting the same exception after upgrading to flutter 3.7.0

JasCodes commented 1 year ago

In next couple of week I am planing to migrate my project to 3.7.0, I will look into it then. Minor flutter updatedate might fix it own its own, feels like regresssion in flutter. For me it only triggers when debugger is attached. In release it works btw.

DavideBelsole commented 1 year ago

Solved. Use the version 0.2.1

JasCodes commented 1 year ago

@DavideBelsole you are awesome