chi11ax
chi11ax

Reputation: 631

Why won't Flutter mobX store code generate?

I have a mobx store and it's really hit and miss getting my storename.g.dart generated.

The first time, I copied an example from medium and just kept running the generator until eventually it gave code.

The second time, I wrote my own store forgot the abstract keyword. Added it in and it worked.

I thought that was the problem.

Now, third project, I think I have all my code down but it's still not generating. Many actions but no output.

What makes it work or fail? This is my current mobx

import 'package:mobx/mobx.dart';
import 'package:firebase_auth/firebase_auth.dart';

// have this line
// then generate with
// flutter packages pub run build_runner build
// or
// flutter packages pub run build_runner clean; flutter packages pub run build_runner build --delete-conflicting-outputs

// todo edit this file name
part 'usermodel.g.dart';

class UserModel = UserModelBase with _$UserModel;

abstract class UserModelBase implements Store {
  @observable
  FirebaseUser user;

  @action
  setUser(FirebaseUser u){
    user = u;
  }

  dispose() {}
}

Upvotes: 1

Views: 3614

Answers (2)

chi11ax
chi11ax

Reputation: 631

I wanted to add an answer in addition to the helpful one @Remi Posted.

When I copied the example, I had copied the entries in pubspec.yaml and it specified mobx 0.1.4 which defined Store as an

abstract class Store {}

However, when I did my third project, I added mobx: without the version and it became 0.2.0 which defined Store as a

mixin Store {
  void dispose() {}
}

Which then required the change of keyword implements to with. Thanks for figuring that out!

Upvotes: 0

Rémi Rousselet
Rémi Rousselet

Reputation: 277037

Store is should be used as a mixin.

Do:

abstract class Foo with Store {}

Don't:

abstract class Foo implements Store {
  void dispose() {} 
} 

Upvotes: 3

Related Questions