### Add Dependencies for json_serializable Source: https://pub.dev/documentation/build_runner/latest Example dependencies to include in pubspec.yaml for using the json_serializable builder. ```yaml dependencies: json_annotation: ^4.9.0 dev_dependencies: build_runner: ^2.6.0 json_serializable: ^6.10.0 ``` -------------------------------- ### Launch build_runner Watch Mode Source: https://pub.dev/documentation/build_runner/latest Command to start build_runner in watch mode, which rebuilds automatically on source code changes. ```bash cd dart run build_runner watch ``` -------------------------------- ### Update Person Class for json_serializable Source: https://pub.dev/documentation/build_runner/latest Example of updating a class to include a new field, demonstrating how watch mode recompiles generated code. ```dart @JsonSerializable() class Person { final String name; final DateTime? dateOfBirth; // Added. final int age; // Updated manually. Person({required this.name, this.dateOfBirth, this.age}); // No change needed, the generated implementations referenced get updated. Map toJson() => _$PersonToJson(this); factory Person.fromJson(Map json) => _$PersonFromJson(json); } ``` -------------------------------- ### Activate json_serializable Builder Source: https://pub.dev/documentation/build_runner/latest Demonstrates how to activate the json_serializable builder using annotations and generated files. ```dart import 'package:json_annotation/json_annotation.dart'; // Include the file that the builder will generate. part 'example.g.dart'; // Activate the builder. @JsonSerializable() class Person { final String name; final DateTime? dateOfBirth; Person({required this.name, this.dateOfBirth}); // Wire up the generated `toJson` in `example.g.dart`. Map toJson() => _$PersonToJson(this); // Wire up the generated `fromJson` in `example.g.dart`. factory Person.fromJson(Map json) => _$PersonFromJson(json); } ``` -------------------------------- ### Perform a Single Build with build_runner Source: https://pub.dev/documentation/build_runner/latest Command to execute a single build using the build_runner CLI. ```bash cd dart run build_runner build ``` -------------------------------- ### Configure Freezed Builder Options Source: https://pub.dev/documentation/build_runner/latest Customize the Freezed builder's behavior, such as controlling output formatting and the generation of copyWith and equality methods. ```yaml targets: $default: builders: freezed: options: # Do format output. format: true # Don't generate `copyWith` or `operator==`. copy_with: false equal: false ``` -------------------------------- ### Configure json_serializable Builder Options Source: https://pub.dev/documentation/build_runner/latest Restrict the json_serializable builder to only run on specific files within your package by specifying a glob pattern. ```yaml targets: $default: builders: json_serializable: generate_for: # Only run `json_serializable` on source under `lib/models`. - lib/models/*.dart ``` -------------------------------- ### Enable Debugging for build_runner Builds Source: https://pub.dev/documentation/build_runner/latest Pass debugging arguments to the Dart VM when running build_runner to enable the Dart DevTools debugger and profiler. ```bash dart run build_runner build --dart-jit-vm-arg=--observe --dart-jit-vm-arg=--pause-isolates-on-start ``` -------------------------------- ### Ignore .dart_tool Directory in Git Source: https://pub.dev/documentation/build_runner/latest Add this line to your .gitignore file to prevent build_runner's internal files from being tracked by Git. ```yaml .dart_tool ``` -------------------------------- ### Dart DevTools Debugger URL Source: https://pub.dev/documentation/build_runner/latest This URL is outputted when debugging is enabled, allowing you to connect to the Dart DevTools for debugging and profiling. ```text The Dart DevTools debugger and profiler is available at: http://127.0.0.1:8181/3xXtAPE8msc=/devtools/?uri=ws://127.0.0.1:8181/3xXtAPE8msc=/ws ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.