Skip to content

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