Questions tagged [built-value]

built_value is a Dart package that provides code generation for reducing boilerplate code when we need to create Value Types. more information here: https://github.com/google/built_value.dart

Built Values for Dart

Built Values provides:

  • Immutable value types;
  • EnumClass, classes that behave like enums;
  • JSON serialization.

Value Types

Value types are, for our purposes, classes that are considered interchangeable if their fields have the same values.

Common examples include Date, Money and Url. Most code introduces its own value types. For example, every web app probably has some version of Account and User.

Value types are very commonly sent by RPC and/or stored for later retrieval.

The problems that led to the creation of the Built Value library have been discussed at great length in the context of AutoValue for Java.

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 oriented design. 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.

47 questions
0
votes
1 answer

How to define fields in a built_value EnumClass?

I wanted to have a EnumClass with an optional message field, something like this: class Status extends EnumClass { static const Status error = _$error; static const Status completed = _$completed; String message; const Status._(String…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
-1
votes
1 answer

Streambuilder not rebuilding after BLOC event

I am trying to implement pagination in my application but I have not been successful in doing so. I am using Firebase, specifically Firestore with the BLOC pattern alongside Built Value which I started using recently to make pagination easier. I…
dotmp3
  • 494
  • 4
  • 13
1 2 3
4