Michael Vo
vo.dev

Follow

vo.dev

Follow
Unions in Dart

Unions in Dart

Michael Vo's photo
Michael Vo
·Nov 12, 2022·

1 min read

A great video explaining how Freezed supports a helpful use case called Unions Video.

Other native languages have features that support a similar use case natively. Swift w/ powerful Enums + associated values Android w/ sealed classes

Unions = multiple classes grouped together

Super useful because it helps the developer:

  1. Avoid having to write exhaustive if/switch statements
  2. Forget supporting a specific case

Below are some example use cases:

Marketing Car: DartPad Screen Shot 2022-11-12 at 6.32.08 AM.png

Screen Shot 2022-11-12 at 6.33.00 AM.png

Result Message (from Video) Screen Shot 2022-11-12 at 6.37.04 AM.png

 
Share this