Aquiko
Aquiko

Reputation: 172

I cant do return inside of a .then

Well I want to return a true state when the username and password match but here's the code

dataBaseHelper.getUserList().then((value) => {
      for(User userOB in value){
        if(userName == userOB.username && password == userOB.password){
          return true
        }
      }
    });

I cannot return inside the .then((value) =>{

}) why? I'm new to flutter BTW

Upvotes: 1

Views: 127

Answers (1)

Prasanna Kumar
Prasanna Kumar

Reputation: 368

You can try using async await instead of then()

var value = await dataBaseHelper.getUserList();
for(User userOB in value){
  if(userName == userOB.username && password == userOB.password){
    return true;
  }
}

Upvotes: 3

Related Questions