Built Values for Dart
Built Values provides immutable "value types" and Enum Classes for Dart and is part of the Libraries for Object Oriented Dart.
Value types are, for our purposes, classes that are considered interchangeable if their fields have the same values.
Common examples include
Url. Most code introduces
its own value types. For example, every web app probably has some
Value types are very commonly sent by RPC and/or stored for later retrieval.
In short: creating and maintaining value types by hand requires a lot of boilerplate. It's boring to write, and if you make a mistake, you very likely create a bug that's hard to track down.
Any solution for value types needs to allow them to participate in object
Date, for example, is the right place for code that
does simple date manipulation.
AutoValue solves the problem for Java with code generation, and Built Values does the same for Dart. The boilerplate is generated for you, leaving you to specify which fields you need and to add code for the behaviour of the class.
Enum Classes provide classes with enum features.
Enums are very helpful in modelling the real world: whenever there are a small fixed set of options, an enum is a natural choice. For an object oriented design, though, enums need to be classes. Dart falls short here, so Enum Classes provide what's missing!
- Constants have
toString, can be used in
switchstatements, and are real classes that can hold code and implement interfaces
valuesmethod that returns all the enum values in a
valueOfmethod that takes a
for a full project with a
build.dart, some example value types and an enum.
Features and bugs
Please file feature requests and bugs at the issue tracker.