Built Values for Dart #
Built Values provides immutable "value types" for Dart and is part of Libraries for Object Oriented Dart.
Value Types #
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.
for a full project with a
build.dart and some example value types.
Features and bugs #
Please file feature requests and bugs at the issue tracker.
- Allow quiver 0.23.
- Upgrade analyzer, build and source_gen dependencies.
- Generate builder if it's not written by hand.
- Make toString append commas for improved clarity.
- Improve examples and tests.
- Fix double null checking.
- Refactor generator to split into logical classes.
- Improve error output on failure to generate.
- Upgrade to source_gen 0.5.0.
- Breaking change; see example for required changes to build.dart.
- Move null checks to "build" method for compatibility with Strong Mode analyzer.
- Allow (and ignore) setters.
- Allow custom factories on value classes.
- Fix for changes to analyzer library.
- Support @nullable for fields using builders.
- Fix constraints for source_gen.
- Allow static fields in value class.
- Allow custom setters in builder.
- Fix error message for missing builder class.
- Allow non-abstract getters in value class.
- Generator, tests and example.
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: built_value_generator: ^0.1.5
2. Install it
You can install packages from the command line:
$ pub get
Alternatively, your editor might support
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Analysis issues and suggestions
Support Dart 2 in
The SDK constraint in
pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.
|Dart SDK||>=1.12.0-dev.5.10 <2.0.0|