How to encode Algebraic Data Types current in Dart?
Algebraic data types are also known as:
- Sealed Classes in Kotlin
- Algebraic Data Types in Scala
- Enums in Rust
- Enums with Associated Values in Swift
- etc etc.
Question is, how do I implement it in current Dart / Flutter, given that support for it has not landed yet (see issue #349)?
There are some approaches explained on the internet, e.g. I've found the match
library, the sealed_unions
library, the if-else
approach, and some more trickier techniques.
But I'd really love some more expert opinions on what to choose, and why did you chose it. Thoughts?