Last updated:
0 purchases
protobuf generator
protobuf_generator #
A flutter generator package to compile Protocol Buffer
files to Dart source code using build_runner (i.e.
the Dart build pipline) without needing to manually install the protoc
compiler or the Dart Protobuf plugin protoc_plugin.
The protobuf_generator package downloads the necessary Protobuf dependencies and googleapis for your platform to a
temporary local directory.
Installation #
Add the necessary dependencies to your pubspec.yaml file:
dependencies:
protobuf: <latest>
protoc_plugin: <latest>
dev_dependencies:
build_runner: <latest>
protobuf_generator: <latest>
copied to clipboard
Configuration #
You must add your .proto files to a build.yaml file next to the pubspec.yaml:
targets:
$default:
sources:
- $package$
- lib/$lib$
- proto/** # Your .proto directory
copied to clipboard
This will use the default configuration for the protobuf_generator.
You may also configure custom options:
targets:
$default:
sources:
- $package$
- lib/$lib$
- proto/**
builders:
protobuf_generator:
options:
# The version of the Protobuf compiler to use.
# (Default: "27.2", make sure to use quotation marks)
protobuf_version: "27.2"
# The version of the Dart protoc_plugin package to use.
# (Default: "21.1.2", make sure to use quotation marks)
protoc_plugin_version: "21.1.2"
# Directory which is treated as the root of all Protobuf files.
# (Default: "proto/")
proto_root_dir: "proto/"
# Include paths given to the Protobuf compiler during compilation.
# (Default: ["proto/"])
proto_paths:
- "proto/"
# The root directory for generated Dart output files.
# (Default: "lib/src/proto")
dart_out_dir: "lib/src/generated"
# Use the "protoc" command that's available on the PATH instead of downloading one
# (Default: false)
use_installed_protoc: false
# Whether or not the protoc_plugin Dart scripts should be precompiled for better performance.
# (Default: true)
precompile_protoc_plugin: true
copied to clipboard
Running #
Once everything is set up, you may simply run the build_runner package:
dart run build_runner build
copied to clipboard
The build_runner sometimes caches results longer than it should, so in some cases, it may be necessary to delete the .dart_tool/build directory.
Contributing #
If you have read up till here, then 🎉🎉🎉. There are couple of ways in which you can contribute to
the growing community of protobuf_generator.dart.
Pick up any issue marked with "good first issue"
Propose any feature, enhancement
Report a bug
Fix a bug
Write and improve some documentation. Documentation is super critical and its importance
cannot be overstated!
Send in a Pull Request 😊
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.