Keep global variable on app close

Hi, I’ve created a file with some global variable inside :

library globals;

bool isLoggedIn = false;
int userId = 0;

I’m changing those variables during the app runtime (if the user is logging… well you know).

But the variable state aren’t keept inside the app when the app is closing.

Is this a good way to save session ? I don’t have to use Firebase for the login, only save a user id in the app (so that I can do some REST API call only thanks to the savec id).

Yes you can save the userid in shared preferences and also the boolean for isLoggedIn and you can check these values on runtime.

https://pub.dev/packages/shared_preferences

Ok so it’s in the shared preference, like in android ! Thanks =)

I’m trying to install shared_preferences, but I have an error with this :

environment:
  sdk: ">=2.1.0 <3.0.0"

The current Flutter SDK version is 1.9.1+hotfix.6.

Because my_app depends on shared_preferences >=0.5.4+9 which requires Flutter SDK version >=1.10.0 <2.0.0, version solving failed.

Any idea how to fix it ?

@Morgan Please try a lower version of the module. You can see the versions here: https://pub.dev/packages/shared_preferences/versions

thanks, i’ll do it. But there’s some security and some functionnaly less so ?