Skip to content

mtbo-org/proto2freezed

Repository files navigation

Prerequisites

  • Install flutter/dart (3.35.1)
  • Install nodejs (v24.6.0)
  • Install quicktype
    # clone quicktype
    git clone https://github.com/mtbo-org/quicktype.git
    cd quicktype
    npm remove -g #if installed previously
    • Windows
      # choose wsl distro
      wsl -l # list
      wsl -d Ubuntu-24.04 npm run build
      npm install -g
    • Linux
      npm run build
      npm install -g
  • Install protoc from https://protobuf.dev/installation/ (32.0)
  • Install go fom https://go.dev/doc/install (1.25.0)
  • Install protoc-gen-jsonschema plugin (v0.5.2)
    #preferred
    go install github.com/pubg/protoc-gen-jsonschema@latest
    #or
    go install github.com/bufbuild/protoschema-plugins/cmd/protoc-gen-jsonschema@latest

Generate

  • Make folder
    mkdir -p lib/src/generated/protobuf
  • Make protobuf dart:
    find . -name "*.proto" -exec protoc -I=proto --dart_out=lib/src/generated/protobuf {} \;
  • Generate schema:
    mkdir -p generated-schema
    protoc  --proto_path=proto --jsonschema_out=generated-schema \
        --jsonschema_opt=entrypoint_message=AddressBook proto/address_book/address_book.proto
  • Generate freezed dart:
    mkdir -p lib/src/generated/schema
    quicktype --src generated-schema/address_book/address_book.schema.json \
        --src-lang schema  \
        --lang dart \
        --top-level AddressBook \
        --use-freezed \
        --out lib/src/generated/schema/address_book.dart
    dart pub get
    dart run build_runner build --delete-conflicting-outputs

About

How to convert protobuf data to dart freezed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages