ssuhat
ssuhat

Reputation: 7656

Flutter Mobx There are no observables detected in the builder function

Hi I got simple obseverable for testing loading state.

abstract class _AccountStore with Store {
  @observable
  bool loadingButtonStatus = false;


  @observable
  bool get loading => loadingButtonStatus;


  @action
  Future updateAccount(formData) async {
    loadingButtonStatus = true;

    Future.delayed(Duration(milliseconds: 2000)).then((future) {
      loadingButtonStatus = false;
    }).catchError((e) {
      loadingButtonStatus = false;
      print(e);
    });
  }
}

here is my widget

AccountStore store = AccountStore();

Observer(
  name: 'loading_button',
  builder: (_) => LoadingButton(
        loading: store.loading,
        text: Text('Save'),
        onPressed: () {
          store.updateAccount({});
        },
))

But everytime i run the code it always return me: There are no observables detected in the builder function

I've tried changed use store.loadingButtonStatus still the same.

any solution?

thanks.

Upvotes: 5

Views: 10389

Answers (4)

Ricardo Fernanddes
Ricardo Fernanddes

Reputation: 1

run this command in terminal

flutter packages pub run build_runner build

Upvotes: 0

PaxLightning
PaxLightning

Reputation: 75

I also have seen this error. Because store_name.g.dart not update.

just run scrip flutter pub run build_runner watch --delete-conflicting-outputs in terminal

Upvotes: 4

Rahul sharma
Rahul sharma

Reputation: 1574

I had same issue but above answer didn't working for me and also Code was correct. my part was not updated.

just run this command in terminal

flutter packages pub run build_runner build

I hope this will work.

Upvotes: 12

Allex Radu
Allex Radu

Reputation: 1540

If you use a getter you are required to use @computed.

  @observable
  bool _loadingButtonStatus = false;


  @computed
  bool get loading => _loadingButtonStatus;

Upvotes: 8

Related Questions