appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
187 stars 214 forks source link

[ BUG ] : _AppinioSwiperState#b3f89(tickers: tracking 1 ticker) was disposed with an active Ticker. #212

Closed csagar131 closed 5 months ago

csagar131 commented 9 months ago

Plugin name appinio_swiper: ^2.1.0

Describe the bug When the end of the card is reached its giving controller active dispose error ═╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown while finalizing the widget tree: _AppinioSwiperState#b3f89(tickers: tracking 1 ticker) was disposed with an active Ticker. _AppinioSwiperState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose(). Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.

To Reproduce Steps to reproduce the behavior:

  1. Swipe the card till end of the list
  2. Switch to different bottom navigation screen
  3. Screen is stuck and can't able to switch between screen by using bottomNavigation

Expected behavior Should be able to switch between screens using bottom navigation bar

Desktop (please complete the following information):

Smartphone (please complete the following information):

stuartrapop commented 8 months ago

I am getting very similar errors. They are not blocking my program, but I am seeing a lot of errors in Crashylitics

I see this on both IOS and Android

Here is the error log.

` ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown while finalizing the widget tree: _AppinioSwiperState#aab31(tickers: tracking 1 ticker) was disposed with an active Ticker. _AppinioSwiperState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose(). Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak. The offending ticker was: _WidgetTicker(created by _AppinioSwiperState#aab31) The stack trace when the _WidgetTicker was actually created was:

0 new Ticker. (package:flutter/src/scheduler/ticker.dart:71:40)

1 new Ticker (package:flutter/src/scheduler/ticker.dart:73:6)

2 new _WidgetTicker (package:flutter/src/widgets/ticker_provider.dart)

3 TickerProviderStateMixin.createTicker

(package:flutter/src/widgets/ticker_provider.dart:296:34)

4 new AnimationController (package:flutter/src/animation/animation_controller.dart:247:21)

5 _AppinioSwiperState._defaultAnimation (package:appinio_swiper/appinio_swiper.dart:168:48)

6 _AppinioSwiperState._onSwipe (package:appinio_swiper/appinio_swiper.dart:190:7)

7 AppinioSwiperController.swipeRight (package:appinio_swiper/appinio_swiper.dart:617:22)

8 _CardDeckPageState.build.swipeRight (package:nameby/screens/cardDeck/card_deck.dart:81:18)

9 RightButton.build..

(package:nameby/screens/cardDeck/SwipeButtons.dart:225:35)

10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)

11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)

12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)

13 BaseTapGestureRecognizer.handlePrimaryPointer

(package:flutter/src/gestures/tap.dart:242:7)

14 PrimaryPointerGestureRecognizer.handleEvent

(package:flutter/src/gestures/recognizer.dart:630:9)

15 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)

16 PointerRouter._dispatchEventToRoutes.

(package:flutter/src/gestures/pointer_router.dart:143:9)

17 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)

18 PointerRouter._dispatchEventToRoutes

(package:flutter/src/gestures/pointer_router.dart:141:18)

19 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)

20 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:488:19)

21 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:468:22)

22 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:439:11)

23 GestureBinding._handlePointerEventImmediately

(package:flutter/src/gestures/binding.dart:413:7)

24 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)

25 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)

26 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)

27 _invoke1 (dart:ui/hooks.dart:328:13)

28 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:410:7)

29 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)

When the exception was thrown, this was the stack:

0 TickerProviderStateMixin.dispose. (package:flutter/src/widgets/ticker_provider.dart:343:13)

1 TickerProviderStateMixin.dispose (package:flutter/src/widgets/ticker_provider.dart:361:6)

2 _AppinioSwiperState.dispose (package:appinio_swiper/appinio_swiper.dart:311:11)

3 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5680:11)

4 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2067:13)

5 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

6 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

7 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

8 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

9 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

10 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

11 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

12 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

13 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

14 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

15 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5523:14)

16 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

17 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

18 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6834:16)

19 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

20 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

21 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

22 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

23 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

24 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

25 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

26 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

27 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6834:16)

28 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

29 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

30 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6722:14)

31 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

32 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

33 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5523:14)

34 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

35 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:2065:7)

36 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5523:14)

37 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2063:13)

38 ListIterable.forEach (dart:_internal/iterable.dart:49:13)

39 _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:2076:25)

40 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2755:15)

41 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3165:7)

42 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:987:19)

43 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)

44 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)

45 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)

46 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)

47 _invoke (dart:ui/hooks.dart:312:13)

48 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)

49 _drawFrame (dart:ui/hooks.dart:283:31)

════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5004 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true. `

LucaL1fe commented 8 months ago

Same here:

The package is quite impressive. If you could address this issue, it would be perfect.

I initially believed that the following code would resolve the issue:

@override void initState() { super.initState(); // initalze quodes event context.read().add(const QuotesInitialized()); controller = AppinioSwiperController(); }

@override void dispose() { controller.dispose(); super.dispose(); }

Unfortunately, it didn't fix the error. I suspect that the ticker needs to be disposed of first from _AppinioSwiperState.

FlutterError (_AppinioSwiperState#cc473(tickers: tracking 1 ticker) was disposed with an active Ticker. _AppinioSwiperState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose(). Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak. The offending ticker was: _WidgetTicker(created by _AppinioSwiperState#cc473) The stack trace when the _WidgetTicker was actually created was: #0 new Ticker. (package:flutter/src/scheduler/ticker.dart:71:40) #1 new Ticker (package:flutter/src/scheduler/ticker.dart:73:6) #2 new _WidgetTicker (package:flutter/src/widgets/ticker_provider.dart) #3 TickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:315:34) #4 new AnimationController (package:flutter/src/animation/animation_controller.dart:247:21) #5 _AppinioSwiperState._animateTo (package:appinio_swiper/appinio_swiper.dart:287:7) #6 AppinioSwiperController.animateTo (package:appinio_swiper/appinio_swiper.dart:652:28) #7 _ExamplePageState._shakeCard (package:studyfueltwo/src/features/quote/presentation/quote_screen.dart:339:22) #8 _ExamplePageState._firstCardShakes. (package:studyfueltwo/src/features/quote/presentation/quote_screen.dart:327:9) #16 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) (elided 7 frames from class _Timer, dart:async, and dart:async-patch))

Thanks for open source this cool package 😊

LucaL1fe commented 8 months ago

I've had frequent errors, prompting me to search for a solution. I must emphasize that what I discovered may not be an ideal solution – it's somewhat unorthodox, and I hesitate to label it as a workaround. However, in my specific case, it appears to be working. I couldn't find a way to address the issue within my code; rather, the modification had to be made in the package's code itself. It's important to note that I'm not familiar with how the code functions, and I can't guarantee its soundness. I simply experimented with it, and it seems to resolve my problem.

In summary:

In the appinio_swiper.dart file (around line 309), I made the following adjustment:

Changed:

@override
void dispose() {
  super.dispose();
  widget.controller?._detach();
  _swipeActivity?.animation.dispose();
}

to:

@override
void dispose() {
  widget.controller?.dispose();
  widget.controller?._detach();
  _swipeActivity?.animation.dispose();
  super.dispose();
}

With this modification, I haven't encountered the error again. However, it's worth noting that while this addresses one issue, there may be potential for other errors to arise. I simply wanted to share my experience.

UPDATE: Got another errors because in Fucntion _startActivity() the controller get diposed too. to handle this i used more code, but its just error handling and no solution, cause of this i don't want to provide the code

When somebody need a quick fix. i made a fork. you can get it with follwing code in your pubspec.yaml:

(but the solution is ugly (shame on me) and i don't recomment it)

dependencies:
  #appinio_swiper: 2.1.0
  appinio_swiper:
    git: 
      url: https://github.com/LucaL1fe/flutter_packages_appinio.git
      path: packages/appinio_swiper

AND no Maintaince! Make a fork for yourself if you want more controll

khanmujeeb687 commented 5 months ago

hey @LucaL1fe , Why did you closed the PR? didn't it worked?

jonmountjoy commented 5 months ago

@csagar131 @LucaL1fe @khanmujeeb687 the following fixes it, but it may break something else that I'm not using:

First, there is an error in the dispose method. The dispose method should only call super as the last thing it does, not the first, so it should change to:

@override
  void dispose() {
    _swipeActivity?.animation.dispose();
    widget.controller?._detach();
    super.dispose();
  }

Second, there is this code:

if (targetIndex >= widget.cardCount && newActivity is Swipe) {
      // We reached the end, do not run the activity.
      if (targetIndex > widget.cardCount && !widget.loop) {
        return;
      }
      // widget.onSwipeEnd?.call(previousIndex, targetIndex, newActivity); << ---- ADD THIS
      widget.onEnd?.call();
      // return;  <<----- ADD THIS RETURN
 }
... /// a whole lot of stuff to do with animations for swiping cards

If you uncomment the two lines I add "ADD THIS", then all the problems go away. I don't know why there is no return there, because there shouldn't be any more cards to animate or work to do?

khanmujeeb687 commented 5 months ago

Hey @jonmountjoy, for me just moving super.dispos() to the end worked. Did you tried this as well?

jonmountjoy commented 5 months ago

I didn't try that - I must admit I went through several hacks trying to locate the problem. Great that that works.