Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example file: animation_full_control.dart Fix #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rdcoder33
Copy link

@rdcoder33 rdcoder33 commented Jun 25, 2022

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();
  }

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 platofrms.
@rdcoder33 rdcoder33 changed the title Using SetState in initState Fix Example file: animation_full_control.dart Fix Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant