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
8
votes
2 answers

Should we commit built_value generated code to git?

built_value generates .g.dart code, but the docs don't give any hints if we should add them to our git repository or not. I think we should, so devs cloning our repo could be up and running, without having to regenerate the code...But some people…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
5
votes
0 answers

Change flutter built_value json naming conventions

I'm consuming an api that uses lowercase_with_underscores naming convention for its jsons' properties: { "user_id": 0, "full_name": "" } and my built_value class is: abstract class User implements Built { //... …
Mahdi Dahouei
  • 1,588
  • 2
  • 12
  • 32
5
votes
1 answer

escape some fileds which are dart keyword

in my application which i connected to server, that return this output: "usertags": { "in": [ { } ] }, in that in is dart keyword and i don't how can i escape that to get data from that and i get this error: error:…
DolDurma
  • 15,753
  • 51
  • 198
  • 377
4
votes
1 answer

flutter pub run build_runner build is Deprecated

When I run flutter pub run build_runner build --delete-conflicting-outputs, I get this error: Deprecated. Use `dart run` instead. [INFO] Generating build script completed, took 169ms [WARNING]…
Mahdi Dahouei
  • 1,588
  • 2
  • 12
  • 32
4
votes
1 answer

Flutter ferry custom scalar serializer "has non-dynamic type"

I'm having a bit of a problem with a custom serializer in flutter ferry graphql package: I have used exactly the example from the ferry docs: https://ferrygraphql.com/docs/custom-scalars/#create-a-custom-serializer But I always get the following…
SimonEritsch
  • 1,047
  • 1
  • 8
  • 22
4
votes
2 answers

How to deserialize Date ISO String to DateTime Object in built_value serialization in dart?

I wanna serialize a json object including an ISOString date to a dart object using built value. this is a sample json: { "title": "test", "description": "test description", "date": "2020-06-05T11:42:38.585Z", "creator": { "email":…
Mahdi Dahouei
  • 1,588
  • 2
  • 12
  • 32
3
votes
2 answers

Error while running built value generator

I got an error while trying to use built value generator This was the error that i got. [INFO] Running build... [INFO] Generating SDK summary. [SEVERE] built value generator:built value on lib/json_parsing.dart: Bad state: Unexpected…
Mr.Despicable
  • 373
  • 1
  • 4
  • 14
3
votes
1 answer

How to serialize with Map using the package built_value

Does anyone know how can I serialize/deserialize a Map instead of String that is the default in the toJson e fromJson methods of the built_value package? I need to use Firestore and the setData method only accepts a Map for the…
JRamos29
  • 880
  • 7
  • 20
3
votes
1 answer

Is there any reasonable way of mixing json_serializable and built_value models in a project?

The problem is as follows, I have a flutter project with some classes using built_value and some classes using json_serializable. Both work fine separately but use very different ways of serializing/deserializing JSON. built_value does its own…
Liminal
  • 1,709
  • 2
  • 12
  • 15
2
votes
1 answer

How to combine the usage of GetX and build_value?

Our app has a lot of provider (https://pub.dev/packages/provider) code which uses built_value (https://pub.dev/packages/built_value) to be able to work with immutable data objects. Now we want to migrate the whole provider functionality to the state…
2
votes
1 answer

How to create nested object using built value

I want to create a nested object to send as request to api. Help is much appreciated. Below is the nested built value class abstract class BuiltUpdateProfileRequest implements Built
Salil Luley
  • 1,361
  • 1
  • 10
  • 10
2
votes
1 answer

Convert error responses to a specific Model - Chopper flutter

i use chopper client for make http requests I written a api, and it have to types of response: success with this format: { "id": 1, "title": "Most Popular phone in the world !", "image": "/uploads/poll_images/D6voYQriTCSZpMIe.jpg", …
2
votes
1 answer

Flutter :type '_InternalLinkedHashMap' is not a subtype of type 'String'

I am trying to user Dio Client for making API calls. While I receive the response It throws an error '_InternalLinkedHashMap' is not a subtype of type 'String' Trying to resolve it but I can't. Below is the code Future get( …
Anbu
  • 671
  • 1
  • 6
  • 18
2
votes
0 answers

Built value generator fails

Since this morning, the generation step of built value (pub run build_runner build) is failing with [SEVERE] built_value_generator:built_value on lib/client.dart (cached): Unknown error in BuiltValueGenerator for…
Jorn
  • 20,612
  • 18
  • 79
  • 126
2
votes
0 answers

Deserialize generic type with Built Value

I have this object : abstract class ApiData implements Built, ApiDataBuilder> { int get offset; int get limit; int get total; int get count; BuiltList get results; ApiData._(); factory…
tufekoi
  • 929
  • 2
  • 14
  • 33
1
2 3 4