1

This is an example of MobX:

import 'package:mobx/mobx.dart';
 
// This is our generated file (we'll see this soon!)
part 'counter.g.dart';
 
// We expose this to be used throughout our project
class Counter = _Counter with _$Counter;
 
// Our store class
abstract class _Counter with Store {
  @observable
  int value = 1;
 
  @action
  void increment() {
    value++;
  }
 
  @action
  void decrement() {
    value--;
  }
}

I don't really understand this code: class Counter = _Counter with _$Counter;.

I know the usage of with, I just don't know why class Counter can be assigned with =, what is the meaning of the assignment operation here? Is this similar to a type alias, or is Counter a subclass of _Counter ? I don't see this usage in Dart's guide.

arcticfox
  • 239
  • 1
  • 2
  • 5

1 Answers1

1

After a slight bit of research I believe the equal sign is a replacement for the extends keyword:

class A = _A with _$A;

is the same as:

class A extends _A with _$A {}
h8moss
  • 4,626
  • 2
  • 9
  • 25