Trying to generate proto to dart file

2,060

Seeing the Flutter tag, I presume that Flutter SDK was what you had before you install Dart SDK as said in your update.

If you want to do this without having to install Dart SDK separately (since Flutter SDK has Dart SDK within itself already), the environment has to know where the following are at:

  • Flutter SDK
    • eg: export PATH="~/desktop/development/flutter/bin:$PATH"
  • Dart SDK within Flutter SDK
    • eg: export PATH="~/desktop/development/flutter/bin/cache/dart-sdk/bin:$PATH"
  • Pub cache within Flutter SDK (where the protoc plugin will be located at)
    • eg: export PATH="$PATH":"$HOME/desktop/development/flutter/.pub-cache/bin"

The given examples above are from .bash_profile in macOS, but in essence, the environment has to know where these 3 are before trying to globally activate the plugin via flutter pub global activate protoc_plugin and then generate Dart code from proto files.

Share:
2,060
hoangquyy
Author by

hoangquyy

Updated on December 13, 2022

Comments

  • hoangquyy
    hoangquyy over 1 year

    I'm trying to generated proto file to dart file with protoc-plugin follow this instruction https://grpc.io/docs/quickstart/dart/ but when I run this command line

    protoc --dart_out=grpc:lib/proto --plugin=protoc-gen-dart=C:/src/flutter/flutter/.pub-cache/bin/protoc-gen-dart.bat -Iprotobuf protobuf/utils.proto
    

    And it showed this error:

    'dart' is not recognized as an internal or external command,
    operable program or batch file.
    'pub' is not recognized as an internal or external command,
    operable program or batch file.
    --dart_out: protoc-gen-dart: Plugin failed with status code 1.
    

    I have installed dart as a plugin in my Android Studio. Is that I have to install dart SDK and add it to environment variable path to work?

    Update

    It worked after i install dart sdk and restart my pc.