alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

was disposed with an active Ticker #662

Closed qq329401134 closed 4 years ago

qq329401134 commented 4 years ago

我在页面想做一个一直旋转的环

===========page============ @override LotteryPageStateStf createState() => LotteryPageStateStf(); state class LotteryPageState implements ObtainGlobalState, Cloneable { AnimationController outController; ============view============ Center( child: RotationTransition( alignment: Alignment.center, turns: state.outController, child: Container( width: 200, height: 200, child: Image( image: AssetImage('assets/lottery/turnplate-bg.png'), fit: BoxFit.cover, ), ), )) ============effect============ void _initState(Action action, Context ctx) { final TickerProvider tickerProvider = ctx.stfState as TickerProvider;

AnimationController outController = AnimationController( duration: Duration(seconds: 1), //时长 vsync: tickerProvider); ///↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ outController.addStatusListener((status) { switch (status) { case AnimationStatus.completed: outController?.reset(); outController?.forward(); break; default: } }); ctx.dispatch(LotteryPageActionCreator.setProperties({ 'outController': outController, })); ctx.state.outController.forward(); } void _dispose(Action action, Context ctx) { ctx.state.outController.dispose(); }

============报错============ ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following assertion was thrown while finalizing the widget tree: LotteryPageStateStf#5238f(ticker active) was disposed with an active Ticker.

LotteryPageStateStf created a Ticker via its SingleTickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. The Ticker 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: Ticker(created by LotteryPageStateStf#5238f(lifecycle state: created)) The stack trace when the Ticker was actually created was:

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

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

2 SingleTickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:95:15)

3 new AnimationController (package:flutter/src/animation/animation_controller.dart:245:21)

4 _initState (package:laozhongjiadao001/lottery_page/effect.dart:21:39)

5 combineEffects. (package:fish_redux/src/redux_component/helper.dart:74:32)

6 createEffectDispatch. (package:fish_redux/src/redux_component/helper.dart:89:39)

7 createDispatch. (package:fish_redux/src/redux_component/helper.dart:109:39)

8 LogicContext.onLifecycle (package:fish_redux/src/redux_component/context.dart:93:5)

9 ComponentContext.onLifecycle (package:fish_redux/src/redux_component/context.dart:204:11)

10 ComponentState.initState (package:fish_redux/src/redux_component/component.dart:222:10)

11 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)

12 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

13 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

14 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

16 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

17 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

18 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

21 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

22 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

23 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

24 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

25 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

28 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

30 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

31 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

33 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

35 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

36 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

37 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

40 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

41 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

42 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

43 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

45 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

46 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

47 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

48 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

50 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

51 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

52 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

53 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

54 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

55 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

56 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

57 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

59 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

60 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

61 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

62 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

63 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

64 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

65 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

66 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

67 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

68 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

69 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

70 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

71 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

72 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

73 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

74 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

75 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

76 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)

77 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

78 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

79 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

80 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

81 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

82 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

83 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

84 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

85 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

86 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

87 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

88 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

89 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

90 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

91 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

92 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

93 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

94 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)

95 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)

96 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)

97 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)

98 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)

99 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5219:32)

100 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)

101 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

102 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:605:16)

103 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

104 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

105 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

106 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)

107 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

108 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

109 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

110 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)

111 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:94:11)

112 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

113 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)

114 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

115 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

116 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

117 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)

118 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

119 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)

120 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

121 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)

122 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

123 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

124 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

125 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)

126 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)

127 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)

128 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)

129 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)

130 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)

131 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)

132 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)

133 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)

134 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)

138 _invoke (dart:ui/hooks.dart:259:10)

139 _drawFrame (dart:ui/hooks.dart:217:3)

(elided 3 frames from package dart:async)

When the exception was thrown, this was the stack:

0 SingleTickerProviderStateMixin.dispose. (package:flutter/src/widgets/ticker_provider.dart:108:7)

1 SingleTickerProviderStateMixin.dispose (package:flutter/src/widgets/ticker_provider.dart:122:6)

2 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4435:12)

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

4 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1746:7)

... ════════════════════════════════════════════════════════════════════════════════════════════════════

请问下是啥问题,我尝试把outController.addStatusListener这一段去掉,就不会报错,这种情况应该怎么处理 还有就是就算addStatusListener那段不添加,在动画还没播放完的情况下退出来一样会报错,但是我的dispose里面dispose的controller了

EaglesChen commented 4 years ago

解决了吗