【问题标题】:"java.lang.IllegalArgumentException: Unsupported value" Exception when accessing FireStore sub-collections访问 FireStore 子集合时出现“java.lang.IllegalArgumentException: Unsupported value”异常
【发布时间】:2018-08-06 07:23:28
【问题描述】:

我有以下 Firestore 集合。

“用户”被添加为对“上传”文档的引用。

这是我使用的代码,当我没有那个“引用”对象时它可以正常工作。

return new StreamBuilder<QuerySnapshot>(
  stream: Firestore.instance
      .collection('uploads')
      .where('type', isEqualTo: type)
      .snapshots,
  builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
      process(snapshot.data.documents);
  });

但是当我添加这个用户引用时,我得到以下 Flutter 异常。

E/AndroidRuntime(11714): java.lang.IllegalArgumentException: Unsupported value: com.google.firebase.firestore.DocumentReference@147888c5
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:260)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:257)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:257)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:249)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:257)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.StandardMethodCodec.encodeMethodCall(StandardMethodCodec.java:31)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:82)
E/AndroidRuntime(11714):        at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:69)
E/AndroidRuntime(11714):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:207)
E/AndroidRuntime(11714):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$EventObserver.onEvent(CloudFirestorePlugin.java:190)
E/AndroidRuntime(11714):        at com.google.firebase.firestore.zzi.onEvent(Unknown Source)
E/AndroidRuntime(11714):        at com.google.android.gms.internal.zzevc.zza(Unknown Source)
E/AndroidRuntime(11714):        at com.google.android.gms.internal.zzevd.run(Unknown Source)
E/AndroidRuntime(11714):        at android.os.Handler.handleCallback(Handler.java:751)
E/AndroidRuntime(11714):        at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(11714):        at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime(11714):        at android.app.ActivityThread.main(ActivityThread.java:6176)
E/AndroidRuntime(11714):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11714):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
E/AndroidRuntime(11714):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

当我将“引用”类型转换为其他类型时,它可以工作。

问题:

如何修改我的代码以获取上传内容及其用户参考详细信息?

【问题讨论】:

    标签: firebase dart google-cloud-firestore flutter


    【解决方案1】:

    实际上,我已经在here 提出了这个问题,它仍然在他们的 github 上显示为 open。在这个阶段,我认为你不能使用reference 类型。也许现在尝试使用ID

    【讨论】:

    • 猜猜这是唯一的解决方案。这对我来说是一个障碍。使用 ID 需要进行额外的呼叫,这是我不想要的。
    • 您能否分享一些关于如何使用 ID 获得更好性能的建议?
    • github.com/flutter/plugins/pull/343 看起来它正在等待批准和合并。
    • @Purus 哦,我没注意到,好消息 :) 希望我们能尽快使用它。无论如何,我们为我们的应用使用 redux,并将集合存储为应用状态,然后在本地按 Id 过滤。
    • 不确定什么时候可以发布 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-05
    • 2020-07-26
    相关资源
    最近更新 更多