Skip to content

BuiltValue deprecation #1164

@subzero911

Description

@subzero911

BuiltValue should be deprecated, because Freezed does the same stuff and more, and much easier and more concise.
It was a good choice in 2018, but now it's undesirable for beginners to drag this outdated package into the modern projects.

BuiltValue has a strange ugly syntax with numerous getters and annotations:

abstract class Person implements Built<Person, PersonBuilder> {
  static Serializer<Person> get serializer => _$personSerializer;

  // Can never be null.
  int get id;

  @nullable
  int get age;

  @nullable
  @BuiltValueField(wireName: 'first_name')
  String get firstName;

  @nullable
  BuiltList<String> get hobbies;

  Person._();
  factory Person([void Function(PersonBuilder) updates]) = _$Person;
}

While Freezed syntax is intuitive and much less verbose:

@freezed
class Person with _$Person {
  const factory Person({
    required String firstName,
    required String lastName,
    required int age,
  }) = _Person;
}

Also it's great for BLoC states declaration:

@freezed
class Union with _$Union {
  const factory Union.data(int value) = Data;
  const factory Union.loading() = Loading;
  const factory Union.error([String? message]) = Error;
}

BuiltValue also has a cumbersome copying through the Builder pattern:

var structuredData = new Account((b) => b
    ..user.update((b) => b
        ..name = 'John Smith')
    ..credentials.phone.update((b) => b
        ..country = Country.us
        ..number = '555 01234 567')
    ..node.left.left.left.account.update((b) => b
        ..user.name = 'John Smith II'
        ..user.nickname = 'Is lost in a tree')
    ..node.left.right.right.account.update((b) => b
        ..user.name = 'John Smith III'));

While Freezed supports a familiar copyWith method

newCompany = company.copyWith.director(name: 'John Doe');

You could continue supporting it, but I suggest you putting the statement "Prefer choosing Freezed" on a main page.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions