Reputation: 7077
I am new to Flutter.
I need to change state in the method 'build'. I am wandering if I need to do it with setState. Also can I initiate navigation in build? On one hand, setState will signal that the component should rebuild. As I am already building it, and building it in a right way, do I need to initiate another rebuilding? If yes, should I exit the method 'build' right after invoking setState?
Upvotes: 2
Views: 690
Reputation: 7077
State changes and navigation should be performed before build: either in initState or in event handlers.
Upvotes: 0
Reputation: 277057
The premise is false: You shouldn't change the state inside build
.
There are clear life-cycles that should be used to do these state changes. Depending on what change accured, you may want to use:
You should use these over build
to do custom work instead.
Upvotes: 2