Flutter 为什么Protobuf的fromJson()函数在Dart中不起作用

Flutter 为什么Protobuf的fromJson()函数在Dart中不起作用,flutter,dart,protocol-buffers,Flutter,Dart,Protocol Buffers,我对fromJson()函数有一个问题 我试图用从Firestore接收到的数据构建protobuf,而fromJson()似乎无法解析它。 面对这个问题,我决定手动创建一个新的空Protobuf,将其导出为JSON,并使用JSON创建一个新的Protobuf。我有一些奇怪的问题: MyProtobuf my_protobuf = MyProtobuf(); my_protobuf.id = "ABC"; ... // Exporting using writeToJson

我对fromJson()函数有一个问题

我试图用从Firestore接收到的数据构建protobuf,而fromJson()似乎无法解析它。 面对这个问题,我决定手动创建一个新的空Protobuf,将其导出为JSON,并使用JSON创建一个新的Protobuf。我有一些奇怪的问题:

MyProtobuf my_protobuf = MyProtobuf();
my_protobuf.id = "ABC";

...
// Exporting using writeToJson()
 String json1 = my_protobuf.writeToJson(); // All my keys are numbers.. why?

// Exporting using a Map
Map<String, dynamic> json2_map = info_to_write.toProto3Json();
String json2 = JsonEncoder().convert(json2_map); // Seems to be a normal JSON

// Build a protobuf from JSON
MyProtobuf new_protobuf1 = MyProtobuf.fromJson(json1);  // Exception thrown
MyProtobuf new_protobuf2 = MyProtobuf.fromJson(json2); // Exception thrown

你能附加你的MyProtobuf类吗?你能解决这个问题吗?您可以附加MyProtobuf类吗?您解决了这个问题吗?谢谢
syntax = "proto3";

package test.v1;

message MyProtobuf {
    string id = 1;
    string name = 2;
}