Flutter“在通知AnimationController的状态侦听器时引发了以下StackOverflowError:堆栈溢出”

时间:2020-10-13 11:13:28

标签: flutter dart animationcontroller

当我在包含使用setState的窗口小部件的页面上调用AnimationController方法时发生了问题。

════════动画库捕获到异常 ═════════════════════════════════
以下StackOverflowError是 通知AnimationController的状态侦听器时抛出:堆栈 溢出

引发异常时,这是堆栈
#0 _WordWrapParseMode.values包: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包:flutter /…/ foundation / diagnostics.dart:856
#4 _PrefixedStringBuilder.write包:flutter /…/ foundation / diagnostics.dart:973
...
的 AnimationController通知状态侦听器为: AnimationController#309d2(⏮0.000;已暂停) ══════════════════════════════════════════════════ ══════════════════════════════

这是我的代码。

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);
                    }
                  }),
              ),
            )
          ],
        ),
      ),
    );
  }
}

0 个答案:

没有答案