sealed_unions: ^3.0.3+1 copied to clipboard
Sealed Unions for Dart
Sealed classes are used for representing restricted class hierarchies, when a value can have one of the types from a limited set, but cannot have any other type. They are, in a sense, an extension of enum classes: the set of values for an enum type is also restricted, but each enum constant exists only as a single instance, whereas a subclass of a sealed class can have multiple instances which can contain state. Sealed classes are available in languages like Kotlin, or C#. Tagged unions are common on Swift and Rust.
This library was heavily inspired by RxEither and the wonderful Domain Driven Design (DDD) talk by Scott Wlaschin. This video by Scott Wlaschin will inspire you on how to apply DDD: Domain Driven Design, F# and Types
The following example project: MVI Sealed Unions demonstrates the library application in a Flutter app.
1. Depend on it
Add this to your package's
dependencies: sealed_unions: "^3.0.3+1"
You can install packages from the command line:
flutter packages get
3. Import it
Now in your Dart code, you can use:
// for example import Union4 import 'package:sealed_unions/union_4.dart';
Copyright (c) fluttercommunity 2019-2021
The Apache Software License, Version 2.0