Are there any sealed classes alternatives in Dart 2.0?

Such use case would be done using named factory constructors.

It requires a lot more code, but the behavior is the same.

class MyState {
  MyState._();

  factory MyState.success(String foo) = MySuccessState;
  factory MyState.error(String foo) = MyErrorState;
}

class MyErrorState extends MyState {
  MyErrorState(this.msg): super._();

  final String msg;
}

class MySuccessState extends MyState {
  MySuccessState(this.value): super._();

  final String value;
}

Leave a Comment

deneme bonusu veren sitelerbahis casino