1

The problem occurred when I called setState method on a page that contains a widget which use AnimationController.

════════ Exception caught by animation library ═════════════════════════════════
The following StackOverflowError was thrown while notifying status listeners for AnimationController: Stack Overflow

When the exception was thrown, this was the stack
#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
...
The AnimationController notifying status listeners was: AnimationController#309d2(⏮ 0.000; paused) ════════════════════════════════════════════════════════════════════════════════

Here's my code.

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

0 Answers0