Home > Blockchain >  How can I get my bool value out of a future<bool>?
How can I get my bool value out of a future<bool>?

Time:04-01

static Future<bool> getLoginStatus() async {
    final prefs = await SharedPreferences.getInstance();
    final status = prefs.getBool('isLoggedIn') ?? false;
    return status;
  }

I have this function as a sharedpreference and I need it to return the bool value, how can I do this?

CodePudding user response:

Use await to obtain bool from Future<bool>.

bool value = await getLoginStatus();

CodePudding user response:

One way of going about this

getLoginStatus().then((bool isLoggedIn){
  // you can used isLoggedIn here
});

Also,

bool isLoggedIn = await getLoginStatus();
// you can used isLoggedIn from here
  • Related