Flutter Mobx There are no observables detected in the builder function

6,253

Solution 1

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

  @observable
  bool _loadingButtonStatus = false;


  @computed
  bool get loading => _loadingButtonStatus;

Solution 2

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.

Solution 3

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

Share:
6,253
ssuhat
Author by

ssuhat

Love to learn a new thing in programming world.

Updated on December 12, 2022

Comments

  • ssuhat
    ssuhat over 1 year

    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.

  • KHAN
    KHAN about 2 years
    Worked for me too! By the way, sometimes flutter packages pub run build_runner build --delete-conflicting-outputs works better too. Give it a go!