proto_generator
10.1.0, released 6 weeks ago by squarealfa.com
Code generation of .proto and Dart mapper classes for using PODOs with gRPC.
What it does
Generates Protocol Buffer .proto files and Dart mapper classes from plain old Dart objects annotated with @proto and @ProtoField. It facilitates seamless serialization between your custom Dart models and gRPC messages, including support for polymorphism and well-known types.
AI-written summary of version 10.1.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a Dart/Flutter application that communicates with gRPC backends
- You want to avoid manually writing boilerplate mapping code between Dart models and gRPC protobuf messages
Skip it when
- You are not using gRPC or protocol buffers in your project
- You prefer writing manual serialization mappers instead of relying on build_runner
Strengths
- Significantly reduces boilerplate for gRPC model mapping
- Supports polymorphism and class inheritance mapping
- Compatible with primary constructors and Google Well Known Types
Weaknesses
- Requires maintaining external tools like protoc compiler and build_runner
- Additional setup steps required outside of standard pub dependency management
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 9
Requires adding proto_annotations and proto_generator, installing the Dart protoc plugin, running build_runner, and compiling proto files manually using protoc.
import 'package:proto_annotations/proto_annotations.dart';
part 'ingredient.proto.dart';
@proto
class Ingredient {
const Ingredient({
required this.description,
required this.quantity,
});
@ProtoField(2)
final String description;
@ProtoField(3)
final double quantity;
}Works with
Packages commonly used together with proto_generator: ones it builds on, ones built on it, and its own family.
- analyzerproto_generator depends on itPerforms static analysis of Dart code for tool integration and embedding.
- globproto_generator depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- dart_styleproto_generator depends on itProvides an API and CLI to format Dart source code automatically.
- buildproto_generator depends on itPackage for authoring build_runner compatible code generators.
- recaseproto_generator depends on itChanges the case of input text to various conventions.
- decimalproto_generator depends on itArbitrary-precision decimal arithmetic for Dart
- grpcproto_generator depends on itDart implementation of gRPC, a high performance universal RPC framework.
- proto_annotationsproto_generator depends on itAnnotations to mark and configure business model classes for code generation of .proto and Dart mappers.