0

I don't understand how to lead to one type my function:

Future<String> getToken(String login) async {
    final data = await (select(authInfos)
          ..where((tbl) => tbl.login.equals(login)))
        .getSingle();
    return data.token;
  }

row with error:

String token = myDatabase.authInfosDao.getToken(login);
steind.VY
  • 333
  • 2
  • 11

1 Answers1

1

For functions that returns a future result you will need to put await on calling it to ensure that the variable will get the return of the said function.

Here's the Syntax:

String token = await myDatabase.authInfosDao.getToken(login);

Update:

Future<void> initState() async {
    // TODO: implement initState
    String token = await myDatabase.authInfosDao.getToken(login);
    super.initState();
}

Note: When using await expression it should be used on an async funtion.

ShinMyth
  • 568
  • 3
  • 6
  • I tried it this way and it gave me this error : "The await expression can only be used in an async function. Try marking the function body with either 'async' or 'async*' " – steind.VY Apr 13 '22 at 06:51
  • Could you provide the code where you implement the call. Usually when you encounter this you just have to add the "async". For example on initState(), I'll edit the answer. – ShinMyth Apr 13 '22 at 07:06