dart_proto 0.1.3
dart_proto: ^0.1.3 copied to clipboard
Dynamic Dart/Flutter protobuf client with generate CLI, HTTP/Connect/gRPC transports, interceptors, and typed errors.
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 #
dart pub add dart_proto
Flutter apps:
flutter pub add dart_proto
That always writes the latest version from pub.flutter-io.cn. If pubspec.yaml still has an older dart_proto, the same command replaces it. Then:
flutter pub get
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/.