In this example, I will share 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 behaviour is the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.