【Flutter】flutter gRPC调研笔记

proto文件编译部分:

  • Dart plugin for the protocol compiler:

    1. Install the protocol compiler plugin for Dart (protoc-gen-dart) using the following command:

      安装针对Dart的protocol编译插件

      $ dart pub global activate protoc_plugin
      
    2. Update your PATH so that the protoc compiler can find the plugin:

      添加到全局变量中

      $ export PATH="$PATH:$HOME/.pub-cache/bin"
      

From the example/helloworld directory, run the following command:

编译一个proto文件

$ protoc --dart_out=grpc:lib/src/generated -Iprotos protos/helloworld.proto

注意:

编译时,必须保证lib/src/generated 这个路径的文件目录是存在的,proto文件必须放到protos目录下

参考

flutter 使用gRPC部分:

Run this command:

With Dart:

 $ dart pub add grpc

With Flutter:

 $ flutter pub add grpc

This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get):

dependencies:
  grpc: ^3.1.0

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:grpc/grpc.dart';

参考

grpc-dart在flutter使用存在的问题

Flutter iOS: Connection was disconnected after changing network state between wifi <> cellular (grpc-dart - version 3.0.2) #564

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值