Dart's built_value library, how to generate the serializer file in flutter?
1,239
In recent versions you need a @SerializersFor()
annotation
See also the example project https://github.com/google/built_value.dart/blob/master/chat_example/lib/data_model/serializers.dart
library serializers;
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:chat_example/data_model/data_model.dart';
part 'serializers.g.dart';
/// Collection of generated serializers for the built_value chat example.
@SerializersFor(const [
Chat,
ListUsers,
ListUsersResponse,
Login,
LoginResponse,
ShowChat,
Status,
Welcome,
])
final Serializers serializers = _$serializers;
Author by
bmhoncho
Updated on December 03, 2022Comments
-
bmhoncho over 1 year
- I've added the built_value dependency.
- I've created a file
serializers.dart
with the serializer field. - I've converted one of my data classes to the required format.
How do I actually build the project to generate the
serializers.g.dart
file?Thanks
-
David Morgan over 6 yearsAnd remember you need to run your build.dart/watch.dart by hand--it's not part of the flutter build process. e.g. run
dart tool/build.dart
. See the example projects for an example build.dart/watch.dart. -
bmhoncho over 6 years@DavidMorgan yes that's what I was missing