我正在尝试使用 Flutter 作为前端构建 Web 应用程序,使用后端和 gRPC 作为通信协议。为了避免在 2 个不同的目录中使用相同的 protobuf,我重构了 protobuf 并将它们编译到客户端和服务器文件夹之外的第三个目录(都在同一个 repo 中)。现在我无法从客户端代码访问已编译的 dart protobufs。这是我的文件夹结构:
.
|-- client/
|-- pubspec.yaml
|-- protos/
|-- dart_protos/
|-- .dart_tool/
|-- .packages
|-- cards.pb.dart
|-- cards.pbenum.dart
|-- cards.pbjson.dart
|-- cards.pbserver.dart
|-- pubspec.lock
|-- pubscpec.yaml
|-- go_protos/
|-- cards.proto
|-- server/
这是我在我的client/pubspec.yaml
dependencies:
flutter:
sdk: flutter
recase: ^4.0.0
search_choices: ^2.0.7
tcb_protos:
path: ../protos/dart_protos
我的protos/dart_protos/pubspec.yaml
:
name: tcb_protos
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
protobuf: ^1.1.4
protoc_plugin: ^19.3.1
以及我如何导入 protobuf:
import 'package:tcb_protos/cards.pb.dart';
所以我遇到了几个问题:
- 我正在
Target of URI hasn't been generated: 'package:tcb_protos/cards.pb.dart'.
进口 - 我无法使用基于导入的 protobuf,并且 VSCode 的智能感知不适用于包(我假设这是因为包定义或导入错误)
如何在 Flutter 小部件中使用 protobuf?