protobuf_generator 1.0.2 copy "protobuf_generator: ^1.0.2" to clipboard
protobuf_generator: ^1.0.2 copied to clipboard

A flutter generator package for generating code for protobuf, without installing protoc and protoc_plugin manually

protobuf_generator #

Pub package publisher

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>

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

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")
          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

Running #

Once everything is set up, you may simply run the build_runner package:

dart run build_runner build

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.

5
likes
0
points
1.03k
downloads

Publisher

verified publisherpub.tamilkannancv.dev

Weekly Downloads

A flutter generator package for generating code for protobuf, without installing protoc and protoc_plugin manually

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

archive, build, flutter, http, path, yaml

More

Packages that depend on protobuf_generator