Mobx.dart: Can action be async and return some value?

Created on 17 Mar 2019  路  1Comment  路  Source: mobxjs/mobx.dart

Can action be asynchronous and return some value? So i can call action somewhere in my code and wait for it to finish and then do something else.

action:

  @action
  Future updateClubs() async {
    var clubs = await ClubService.getClubs(userId,token);
    listOfClubs = clubs;
    return listOfClubs;
  }

and then call it somewhere in my code:

var x = await store.updateClubs();
then do something else...

On await it says "The await expression can only be used in an asynchronous function.".

Am i missing something? Im new to concept of mobx :)

Most helpful comment

It's definitely possible. You can see it being used in here.

In your case, make it more type-safe by changing your return type to Future<List<Club>> or something along those lines.

BTW, its good to go through the examples source code. Many of the typical use cases have been covered there.

>All comments

It's definitely possible. You can see it being used in here.

In your case, make it more type-safe by changing your return type to Future<List<Club>> or something along those lines.

BTW, its good to go through the examples source code. Many of the typical use cases have been covered there.

Was this page helpful?
0 / 5 - 0 ratings