xvrh / lottie-flutter

Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.
https://pub.dev/packages/lottie
MIT License
1.16k stars 196 forks source link

Example file: animation_full_control.dart Fix #221

Open rdcoder33 opened 2 years ago

rdcoder33 commented 2 years ago

For example file example >> lib >> animation_full_control.dart

Using SetState in initState cause the following error setState() or markNeedsBuild() called when widget tree was locked.

I have added a WidgetsBinding.instance.addPostFrameCallback wrapper to fix it. It's tested and work fine on all platforms.

@override
  void initState() {
    _controller = AnimationController(vsync: this);
    WidgetsBinding.instance.addPostFrameCallback((_) => setState(() {
          _controller
            .addListener(() {
              setState(() {
                // Rebuild the widget at each frame to update the "progress" label.
              });
            });
        }));

    super.initState();
  }