dart_proto
A Dart / Flutter client for protobuf APIs.
Point it at your .proto files (local folder, GitHub, or Buf), generate typed
client methods, and call your server:
final user = await api.userService.getUser({'id': '1'});
- GitHub: https://github.com/vishalsharma7nov/dart-proto
- pub.flutter-io.cn: https://pub.flutter-io.cn/packages/dart_proto
- License: MIT
Install
dependencies:
dart_proto: ^0.1.0
Quick start
1. Config (in your app, not in the package)
import 'package:dart_proto/dart_proto.dart';
final config = ProtoClientConfig(
baseUrl: 'https://api.example.com',
protoSource: ProtoSource.local('protos'),
getHeaders: () async => {
'Authorization': 'Bearer ${await getToken()}',
},
);
2. Call your API
import 'package:dart_proto/dart_proto.dart';
final api = createApi(config);
try {
final user = await api.userService.getUser({'id': '1'});
print(user);
} catch (e) {
if (isProtoClientError(e)) {
print(e);
}
}
Generate from your own protos
dart run dart_proto generate --out ./lib/generated
dart run dart_proto generate --from local --path ./protos --out ./lib/generated
dart run dart_proto watch --from local --path ./protos --out ./lib/generated
dart run dart_proto generate --from github --repo https://github.com/you/protos.git --ref v1.0.0 --out ./lib/generated
dart run dart_proto generate --from buf --module buf.build/acme/petapis --ref 1.0.0 --out ./lib/generated
Your .proto files must include service and rpc blocks.
Docs
Full documentation lives in the repo under docs/.
Libraries
- dart_proto
- mock_server
- Mock protobuf HTTP server for demos and tests.
- riverpod
- Optional Flutter Riverpod helpers for dart_proto.