Ask Your Question
1

Why doesn't a build get triggered when using setState() in Flutter?

asked 2023-05-27 09:43:03 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-27 09:47:01 +0000

woof gravatar image

A build is not triggered immediately after calling setState() in Flutter because setState() is an asynchronous method that triggers a rebuild request. The Flutter framework combines multiple rebuild requests that occur within a short amount of time and then schedules a batched rebuild. This is done to improve performance and avoid multiple unnecessary rebuilds.

Additionally, after calling setState(), the framework checks if the state of the widget has actually changed. If there is no change, then a rebuild is not triggered, as this would be unnecessary and inefficient.

Overall, the Flutter framework is designed to optimize the number of rebuilds and reduce the performance overhead of setState() calls.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-27 09:43:03 +0000

Seen: 10 times

Last updated: May 27 '23