[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-9537":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":26,"discoverSource":27},9537,"built_value.dart","google\u002Fbuilt_value.dart","google","Immutable value types, enum classes, and serialization.","https:\u002F\u002Fpub.dev\u002Fpackages\u002Fbuilt_value",null,"Dart",886,190,14,90,0,2,10.84,"BSD 3-Clause \"New\" or \"Revised\" License",false,"master",[],"2026-06-12 02:02:08","[![Build](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Factions\u002Fworkflows\u002Fbuild.yaml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Factions\u002Fworkflows\u002Fbuild.yaml)\n\n## Built Values for Dart - Introduction\n\nBuilt Value provides:\n\n- Immutable value types;\n- EnumClass, classes that behave like enums;\n- JSON serialization.\n\nImmutable collections are from\n[built_collection](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_collection.dart#built-collections-for-dart).\n\nSee the [API docs](https:\u002F\u002Fpub.dev\u002Fdocumentation\u002Fbuilt_value\u002Flatest\u002Fbuilt_value\u002Fbuilt_value-library.html).\n\n## Articles\n\n- [`built_value` for Immutable Object Models](https:\u002F\u002Fmedium.com\u002F@davidmorgan_14314\u002Fdarts-built-value-for-immutable-object-models-83e2497922d4#.48dyezxcl)\n- [`built_value` for Serialization](https:\u002F\u002Fmedium.com\u002F@davidmorgan_14314\u002Fdarts-built-value-for-serialization-f5db9d0f4159#.h12y94wu7)\n- [Building a Chat App in Dart](https:\u002F\u002Fmedium.com\u002F@davidmorgan_14314\u002Fbuilding-a-chat-app-in-dart-815fcd0e5a31#.ku4vtbmk2)\n- [End to End Testing in One Short Second with Dart](https:\u002F\u002Fmedium.com\u002F@davidmorgan_14314\u002Fend-to-end-testing-in-one-short-second-with-dart-e699c8146fd6#.c7xfxohg4)\n- [Moving Fast with Dart Immutable Values](https:\u002F\u002Fmedium.com\u002F@davidmorgan_14314\u002Fmoving-fast-with-dart-immutable-values-1e717925fafb)\n- [Flutter JSON Serialization](https:\u002F\u002Faloisdeniel.github.io\u002Fflutter-json-serialization\u002F)\n- [Flutter TODO App Example](https:\u002F\u002Fgitlab.com\u002Fbrianegan\u002Fflutter_architecture_samples\u002Ftree\u002Fmaster\u002Fexample\u002Fbuilt_redux)\n  using `built_value`, [built_redux](https:\u002F\u002Fpub.dev\u002Fpackages\u002Fbuilt_redux), and [flutter_built_redux](https:\u002F\u002Fpub.dev\u002Fpackages\u002Fflutter_built_redux)\n- [Building a (large) Flutter app with Redux](https:\u002F\u002Fhillelcoren.com\u002F2018\u002F06\u002F01\u002Fbuilding-a-large-flutter-app-with-redux\u002F)\n- [Some Options for Deserializing JSON with Flutter](https:\u002F\u002Fmedium.com\u002Fflutter-io\u002Fsome-options-for-deserializing-json-with-flutter-7481325a4450)\n\n## Tutorials\n\n - [Custom Serializers](https:\u002F\u002Fmedium.com\u002F@solid.goncalo\u002Fcreating-custom-built-value-serializers-with-builtvalueserializer-46a52c75d4c5)\n - [Flutter + built_value + Reddit Tutorial](https:\u002F\u002Fsteemit.com\u002Futopian-io\u002F@tensor\u002Fbuilding-immutable-models-with-built-value-and-built-collection-in-dart-s-flutter-framework);\n   [video](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=hNbOSSgpneI);\n   [source code](https:\u002F\u002Fgithub.com\u002Ftensor-programming\u002Fbuilt_flutter_tutorial)\n\n## Tools\n\n - [Json to Dart built_value class converter](https:\u002F\u002Fcharafau.github.io\u002Fjson2builtvalue\u002F)\n - [Json or js Object to Dart built_value class converter](https:\u002F\u002Fjanuwa.github.io\u002Fp5_object_2_builtvalue\u002Findex.html)\n- [VSCode extension](https:\u002F\u002Fmarketplace.visualstudio.com\u002Fitems?itemName=GiancarloCode.built-value-snippets)\n - [IntelliJ plugin](https:\u002F\u002Fplugins.jetbrains.com\u002Fplugin\u002F13786-built-value-snippets)\n\n## Examples\n\nFor an end to end example see the\n[chat example](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Ftree\u002Fmaster\u002Fchat_example), which was\n[demoed](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=TMeJxWltoVo) at the Dart Summit 2016.\nThe\n[data model](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Fblob\u002Fmaster\u002Fchat_example\u002Flib\u002Fdata_model\u002Fdata_model.dart),\nused both client and server side, uses value types, enums and serialization from\nbuilt_value.\n\nSimple examples are\n[here](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Ftree\u002Fmaster\u002Fexample\u002Flib\u002Fexample.dart).\n\n## Codegen\n\nCodegen is done using `dart run build_runner build` for one-off builds. \n\nTo continuously watch your source and update the generated output when it changes, use `dart run build_runner watch`.\n\nNote that you need a dev dependency on `built_value_generator` and `build_runner`. See the example\n[pubspec.yaml](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Fblob\u002Fmaster\u002Fexample\u002Fpubspec.yaml).\n\n## Value Types\n\nValue types are, for our purposes, classes that are considered\ninterchangeable if their fields have the same values.\n\nCommon examples include `Date`, `Money` and `Url`. Most code introduces\nits own value types. For example, every web app probably has some\nversion of `Account` and `User`.\n\nValue types are very commonly sent by RPC and\u002For stored for later\nretrieval.\n\nThe problems that led to the creation of the Built Value library have\nbeen\n[discussed at great length](https:\u002F\u002Fdocs.google.com\u002Fpresentation\u002Fd\u002F14u_h-lMn7f1rXE1nDiLX0azS3IkgjGl5uxp5jGJ75RE\u002Fedit)\nin the context of\n[AutoValue](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fauto\u002Ftree\u002Fmaster\u002Fvalue#autovalue)\nfor Java.\n\nIn short: creating and maintaining value types by hand requires a lot of\nboilerplate. It's boring to write, and if you make a mistake, you very\nlikely create a bug that's hard to track down.\n\nAny solution for value types needs to allow them to participate in object\noriented design. `Date`, for example, is the right place for code that\ndoes simple date manipulation.\n\n[AutoValue](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fauto\u002Ftree\u002Fmaster\u002Fvalue#autovalue)\nsolves the problem for Java with code generation, and Built Values does\nthe same for Dart. The boilerplate is generated for you, leaving you to\nspecify which fields you need and to add code for the behaviour of the\nclass.\n\n### Generating boilerplate for Value Types\n\nValue types require a bit of boilerplate in order to connect it to generated\ncode. Luckily, even this bit of boilerplate can be automated using code\nsnippets support in your favourite text editor. For example, in IntelliJ you\ncan use the following live template:\n\n```dart\nabstract class $CLASS_NAME$ implements Built\u003C$CLASS_NAME$, $CLASS_NAME$Builder> {\n  $CLASS_NAME$._();\n  factory $CLASS_NAME$([void Function($CLASS_NAME$Builder) updates]) = _$$$CLASS_NAME$;\n}\n```\n\nUsing this template, you would only have to manually enter a name for your data\nclass, which is something that can't be automated.\n\n## Enum Class\n\nEnum Classes provide classes with enum features.\n\nEnums are very helpful in modelling the real world: whenever there are a\nsmall fixed set of options, an enum is a natural choice. For an object\noriented design, though, enums need to be classes. Dart falls short here,\nso Enum Classes provide what's missing!\n\nDesign:\n\n- Constants have `name` and `toString`, can be used in `switch` statements,\n  and are real classes that can hold code and implement interfaces\n- Generated `values` method that returns all the enum values in a `BuiltSet` (immutable set)\n- Generated `valueOf` method that takes a `String`\n\n## Serialization\n\nBuilt Values comes with JSON serialization support which allows you to\nserialize a complete data model of Built Values, Enum Classes and\nBuilt Collections. The\n[chat example](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Ftree\u002Fmaster\u002Fchat_example) shows \nhow easy this makes building a full application with Dart on the server and\nclient.\n\nHere are the major features of the serialization support:\n\nIt _fully supports object oriented design_: any object model that you can \ndesign can be serialized, including full use of generics and interfaces.\nSome other libraries require concrete types or do not fully support generics.\n\nIt _allows different object oriented models over the same data_. For\nexample, in a client server application, it's likely that the client and server\nwant different functionality from their data model. So, they are allowed to have\ndifferent classes that map to the same data. Most other libraries enforce a 1:1\nmapping between classes and types on the wire.\n\nIt _requires well behaved types_. They must be immutable, can use\ninterface but not concrete inheritance, must have predictable nullability,\n`hashCode`, `equals` and `toString`. In fact, they must be Enum Classes, Built\nCollections or Built Values. Some other libraries allow badly behaved types to\nbe serialized.\n\nIt _supports changes to the data model_. Optional fields can be added or\nremoved, and fields can be switched from optional to required, allowing your\ndata model to evolve without breaking compatbility. Some other libraries break\ncompatibility on any change to any serializable class.\n\nIt's _modular_. Each endpoint can choose which classes to know about;\nfor example, you can have multiple clients that each know about only a subset of\nthe classes the server knows. Most other libraries are monolithic, requiring all\nendpoints to know all types.\n\nIt _has first class support for validation_ via Built Values. An important \npart of a powerful data model is ensuring it's valid, so classes can make\nguarantees about what they can do. Other libraries also support validation\nbut usually in a less prominent way.\n\nIt's _pluggable_. You can add serializers for your own types, and you can add\n[plugins](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Fblob\u002Fmaster\u002Fbuilt_value\u002Flib\u002Fstandard_json_plugin.dart)\nwhich run before and after all serializers. This could be used to\ninteroperate with other tools or to add hand coded high performance serializers\nfor specific classes. Some other libraries are not so extensible.\n\nIt was designed to be _multi language_, mapping to equivalent object models in\nJava and other languages. Currently only Dart is supported. The need for other\nlanguages didn't materialize as servers are typically either written in Dart\nor owned by third parties. Please open an issue if you'd like to explore\nsupport in more languages.\n\n## Common Usage\n\nWhile full, compiled examples are available in\n[`example\u002Flib`](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Ftree\u002Fmaster\u002Fexample\u002Flib),\na common usage example is shown here. This example assumes that you are writing\na client for a JSON API representing a person that looks like the following:\n\n```json\n{\n  \"id\": 12345,\n  \"age\": 35,\n  \"first_name\": \"Jimmy\",\n  \"hobbies\": [\"jumping\", \"basketball\"]\n}\n```\n\nThe corresponding dart class employing `built_value` might look like this. Note\nthat it is using the\n[`@BuiltValueField`](https:\u002F\u002Fpub.dev\u002Fdocumentation\u002Fbuilt_value\u002Flatest\u002Fbuilt_value\u002FBuiltValueField-class.html)\nannotation to map between the property name on the response and the name of the\nmember variable in the `Person` class.\n\n```dart\nimport 'package:built_value\u002Fbuilt_value.dart';\nimport 'package:built_value\u002Fserializer.dart';\nimport 'package:built_collection\u002Fbuilt_collection.dart';\n\npart 'person.g.dart';\n\nabstract class Person implements Built\u003CPerson, PersonBuilder> {\n  static Serializer\u003CPerson> get serializer => _$personSerializer;\n\n  int get id;\n\n  int? get age;\n\n  @BuiltValueField(wireName: 'first_name')\n  String? get firstName;\n\n  BuiltList\u003CString> get hobbies;\n\n  Person._();\n  factory Person([void Function(PersonBuilder) updates]) = _$Person;\n}\n```\n\n## FAQ\n\n### How do I check a field is valid on instantiation?\n\nThe value class private constructor runs when all fields are initialized and\ncan do arbitrary checks:\n\n```dart\nabstract class MyValue {\n  MyValue._() {\n    if (field \u003C 0) {\n      throw ArgumentError(field, 'field', 'Must not be negative.');\n    }\n  }\n```\n\n### How do I process a field on instantiation?\n\nAdd a hook that runs immediately before a builder is built. For example, you\ncould sort a list, so it's always sorted directly before the value is created:\n\n```dart\nabstract class MyValue {\n  @BuiltValueHook(finalizeBuilder: true)\n  static void _sortItems(MyValueBuilder b) =>\n      b..items.sort();\n```\n\n### How do I set a default for a field?\n\nAdd a hook that runs whenever a builder is created:\n\n```dart\nabstract class MyValue {\n  @BuiltValueHook(initializeBuilder: true)\n  static void _setDefaults(MyValueBuilder b) =>\n      b\n        ..name = 'defaultName'\n        ..count = 0;\n```\n\n### Should I check in and\u002For publish in the generated `.g.dart` files?\n\nSee the [build_runner](https:\u002F\u002Fpub.dev\u002Fpackages\u002Fbuild_runner#source-control)\ndocs. You usually should not check in generated files, but you _do_ need to publish\nthem.\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[tracker]: https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbuilt_value.dart\u002Fissues\n","google\u002Fbuilt_value.dart 是一个用于 Dart 语言的库，提供了不可变值类型、枚举类以及 JSON 序列化功能。其核心特性包括生成不可变对象模型、支持类似枚举的行为的 EnumClass 以及高效的序列化机制，这使得它非常适合于需要确保数据一致性与线程安全的应用场景中使用，如 Flutter 应用开发中的状态管理或后端服务的数据处理。此外，通过结合 built_collection 库，还可以轻松创建不可变集合。该工具对于构建复杂但易于维护的应用程序架构特别有用，尤其是在涉及大量数据交换和处理的情况下。","2026-06-11 03:23:16","top_language"]