I want to know whether it's ok to do or I should not do. For example I created class like this:
class Utils {
static String uid;
}
And get the user's uniqueId
when user logged in and set it like so:
Utils.uid = uniqueId;
After that, just pass around.
Let's say I have there tabs and starts with first tab which get uid
here and when go to second tab, use uid
for something.
Is it something I should not do or is it ok?
Any help is appreciated!
No. In general inside Flutter, everything should be coming from a widget. Be it configurations, API data, authentification, or whatever you can think of.
While you could make it work with singletons/static properties, you loose a lot. By wrapping everything inside a widget; it ensures that whenever the data change, everything gets reloaded correctly.
In this situation you'll want to expose user informations using an InheritedWidget
.
More informations here on how to use them.
I can't really say wether it's right or wrong cause it depends, but what I am doing and I've seen several others do is to store the user related info like user id in SharedPreferences once the user logs into the application.
Hope this was helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With