Reputation: 1
My question to understand if I have some data like login info that I will not change along with app live. But I will use it in many different screens why use state management instead of using a static variable to store data and retrieve. I hope to find an answer or guidance to the appropriate article or documentation.
Upvotes: 0
Views: 56
Reputation: 531
State Management in simple terms is defined as 'Whatever data you need to rebuild your UI at any moment'. State Management makes it easier to access data and helps you to keep your business logic and UI separate.
Now to your question If you use state management like Provider etc, you can access your login data globally and wouldn't have to pass a static variable to all screens. With help of state management, your rebuilds will also be smaller rather than building a whole screen again
Upvotes: 1
Reputation: 44220
You can certainly store it in the State of a StatefulWidget, so it can be accessed by the corresponding build() method. But to have a broader scope, you'll need something like Provider or (my preferred) Riverpod.
Upvotes: 0