### Example pubspec.yaml Dependency Source: https://pub.dev/packages/built_value/install This is an example of how the built_value dependency will appear in your pubspec.yaml file. ```yaml dependencies: built_value: ^8.12.6 ``` -------------------------------- ### Define a Serializable Person Class with Built Value Source: https://pub.dev/packages/built_value_generator This example demonstrates how to define a Dart class using `built_value` for JSON serialization. It uses the `@BuiltValueField` annotation to map JSON keys to Dart member variables and includes a `BuiltList` for hobbies. ```dart import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; import 'package:built_collection/built_collection.dart'; part 'person.g.dart'; abstract class Person implements Built { static Serializer get serializer => _$personSerializer; int get id; int? get age; @BuiltValueField(wireName: 'first_name') String? get firstName; BuiltList get hobbies; Person._(); factory Person([void Function(PersonBuilder) updates]) = _$Person; } ``` -------------------------------- ### Process a Field Before Instantiation with Built Value Hook Source: https://pub.dev/packages/built_value_generator Utilize the `@BuiltValueHook(finalizeBuilder: true)` annotation to execute custom logic just before a builder is finalized and the value is created. This example sorts a list of items. ```dart abstract class MyValue { @BuiltValueHook(finalizeBuilder: true) static void _sortItems(MyValueBuilder b) => b..items.sort(); ``` -------------------------------- ### Generate Built Value Types with build_runner Source: https://pub.dev/packages/built_value_generator Use `dart run build_runner build` for one-off builds or `dart run build_runner watch` to continuously update generated output when source files change. Requires `built_value_generator` and `build_runner` as dev dependencies. ```bash dart run build_runner build ``` ```bash dart run build_runner watch ``` -------------------------------- ### Boilerplate for Value Types Source: https://pub.dev/packages/built_value_generator This live template from IntelliJ can be used to generate the basic structure for a value type class. You only need to manually enter the data class name. ```dart abstract class $CLASS_NAME$ implements Built<$CLASS_NAME$, $CLASS_NAME$Builder> { $CLASS_NAME$._(); factory $CLASS_NAME$([void Function($CLASS_NAME$Builder) updates]) = _$$$CLASS_NAME$; } ``` -------------------------------- ### Add built_value to Flutter Project Source: https://pub.dev/packages/built_value/install Use this command to add built_value as a dependency in a Flutter project. ```bash $ flutter pub add built_value ``` -------------------------------- ### Add built_value to Dart Project Source: https://pub.dev/packages/built_value/install Use this command to add built_value as a dependency in a Dart project. ```bash $ dart pub add built_value ``` -------------------------------- ### Add built_value_generator to Flutter Project Source: https://pub.dev/packages/built_value_generator/install Use this command to add the package as a dev dependency in a Flutter project. ```bash flutter pub add built_value_generator ``` -------------------------------- ### Add built_value_generator to Dart Project Source: https://pub.dev/packages/built_value_generator/install Use this command to add the package as a dev dependency in a Dart project. ```bash dart pub add built_value_generator ``` -------------------------------- ### Import built_value_generator in Dart Code Source: https://pub.dev/packages/built_value_generator/install Import the necessary library into your Dart files to use its functionalities. ```dart import 'package:built_value_generator/built_value_generator.dart'; ``` -------------------------------- ### Import built_value in Dart Code Source: https://pub.dev/packages/built_value/install Include this import statement in your Dart files to use the built_value library. ```dart import 'package:built_value/built_value.dart'; ``` -------------------------------- ### Validate a Field on Instantiation Source: https://pub.dev/packages/built_value_generator Use the private constructor of a value class to perform arbitrary checks on fields when an instance is created. This ensures data integrity by throwing an `ArgumentError` if a condition is not met. ```dart abstract class MyValue { MyValue._() { if (field < 0) { throw ArgumentError(field, 'field', 'Must not be negative.'); } } ``` -------------------------------- ### Set Default Field Values on Builder Creation Source: https://pub.dev/packages/built_value_generator Employ the `@BuiltValueHook(initializeBuilder: true)` annotation to run a hook when a builder is initialized. This allows setting default values for fields, ensuring they have a predictable state. ```dart abstract class MyValue { @BuiltValueHook(initializeBuilder: true) static void _setDefaults(MyValueBuilder b) => b ..name = 'defaultName' ..count = 0; ``` -------------------------------- ### Dart Static Analysis Warning Source: https://pub.dev/packages/built_value/score This code snippet shows a static analysis warning related to variable naming conventions in Dart. It indicates that the variable name 'Map' is not in lowerCamelCase. ```dart Iterable serialize(Serializers serializers, Map Map, ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.