我正在将Flushbar plugin用于Flutter。
该插件效果很好,但是我不明白如何重复附加到其上的动画控制器播放的动画。
AnimationController _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: Duration(seconds: 3),
);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void showFlushBar() {
Flushbar(
titleText: Text(
"Title",
style: TextStyle(
fontFamily: 'Futura',
color: Colors.white,
fontSize: MediaQuery.of(context).size.width / 18),
),
messageText: Text(
"Message"
style: TextStyle(
fontFamily: 'Futura',
color: Colors.white,
fontSize: MediaQuery.of(context).size.width / 25),
),
showProgressIndicator: true,
progressIndicatorBackgroundColor: Colors.blueGrey,
progressIndicatorController: _controller,
)..show(context);
_controller.forward();
}
第一次动画效果良好,但是从第二次出现此错误:
E/flutter (29680): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 451 pos 7: '_ticker != null': AnimationController.forward() called after AnimationController.dispose()
E/flutter (29680): AnimationController methods should not be used after calling dispose.
E/flutter (29680): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
E/flutter (29680): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:38:5)
E/flutter (29680): #2 AnimationController.forward (package:flutter/src/animation/animation_controller.dart:451:7)
E/flutter (29680): #3 _SettingsScreenState._changeLanguage (package:formula1_fan_assistant/screens/settings_screen.dart:401:19)
E/flutter (29680): #4 _asyncThenWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:73:64)
E/flutter (29680): #5 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (29680): #6 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (29680): #7 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
E/flutter (29680): #8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
E/flutter (29680): #9 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
E/flutter (29680): #10 Future._completeWithValue (dart:async/future_impl.dart:524:5)
E/flutter (29680): #11 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:32:15)
E/flutter (29680): #12 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:290:13)
E/flutter (29680): #13 _SettingsScreenState.myLoadAsset (package:formula1_fan_assistant/screens/settings_screen.dart)
E/flutter (29680): #14 _asyncErrorWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:80:45)
E/flutter (29680): #15 _rootRunBinary (dart:async/zone.dart:1146:38)
E/flutter (29680): #16 _CustomZone.runBinary (dart:async/zone.dart:1039:19)
E/flutter (29680): #17 _FutureListener.handleError (dart:async/future_impl.dart:153:20)
E/flutter (29680): #18 Future._propagateToListeners.handleError (dart:async/future_impl.dart:692:47)
E/flutter (29680): #19 Future._propagateToListeners (dart:async/future_impl.dart:713:24)
E/flutter (29680): #20 Future._addListener.<anonymous closure> (dart:async/future_impl.dart:389:9)
E/flutter (29680): #21 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (29680): #22 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (29680): #23 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (29680): #24 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (29680): #25 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (29680): #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (29680):
我真的找不到解决方案,无论是在S.O上。或Internet上其他任何地方,请帮助我。
预先感谢
答案 0 :(得分:0)
我解决了这个问题! mixin出现了问题:我正在使用SingleTickerProviderStateMixin
,为此我需要一个TickerProviderStateMixin
。