当我setState
在包含使用AnimationController
.
════════ 动画库捕捉到的异常═════════════════════════════════在通知 AnimationController 的状态侦听器时引发以下 StackOverflowError:堆栈溢出
抛出异常时,这是堆栈
#0 _WordWrapParseMode.values package:flutter/.../foundation/diagnostics.dart:776
#1 _SyncIterator.moveNext (dart:core-patch/core_patch.dart:165:25))
# 2 Iterable.length (dart:core/iterable.dart:429:15))
#3 _PrefixedStringBuilder._finalizeLine package:flutter/…/foundation/diagnostics.dart:856
#4 _PrefixedStringBuilder.write package:flutter/…/foundation/diagnostics .dart:973
...
AnimationController 通知状态监听器是:AnimationController#309d2(⏮ 0.000; paused) ═══════════════════════════ ══════════════════════════════════════════════════ ═══
这是我的代码。
class SecurityHeaderComponent extends StatefulWidget {
SecurityHeaderComponent({Key key}) : super(key: key);
@override
_SecurityHeaderComponentState createState() =>
_SecurityHeaderComponentState();
}
class _SecurityHeaderComponentState extends State<SecurityHeaderComponent>
with TickerProviderStateMixin {
AnimationController _oRotateController;
AnimationController _iRotateController;
@override
void initState() {
_oRotateController = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_oRotateController.forward();
_iRotateController = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_iRotateController.reverse(from: _iRotateController.upperBound);
super.initState();
}
@override
void dispose() {
_oRotateController.dispose();
_iRotateController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
height: 200.0,
decoration: BoxDecoration(color: MyColors.tb_security_blue_color),
child: Center(
child: Stack(
children: [
Center(
child: Image(
image: ImageUtils.getAssetImage("1fixed_safetyprotection"),
width: 130,
height: 130,
),
),
Center(
child: RotationTransition(
child: Image(
image: ImageUtils.getAssetImage('circle_13@3x'),
width: 188,
height: 188,
),
turns: _oRotateController
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_oRotateController.reset();
_oRotateController.forward();
}
}),
),
),
Center(
child: RotationTransition(
child: Image(
image: ImageUtils.getAssetImage('circle_23@3x'),
width: 136,
height: 136,
),
turns: _iRotateController
..addStatusListener((status) {
if (status == AnimationStatus.dismissed) {
_iRotateController.reset();
_iRotateController.reverse(
from: _iRotateController.upperBound);
}
}),
),
)
],
),
),
);
}
}