Flutter Firestore错误:MissingPluginException(未找到方法DocumentReference#updateData的实现

时间:2020-06-21 18:41:46

标签: firebase flutter

我正在尝试更新文档并不断出现此错误:

ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method DocumentReference#updateData on channel plugins.flutter.io/cloud_firestore

这就是我想要做的:

Firestore.instance.collection('myCollection').document(documentID).updateData({"fieldName": FieldValue.arrayUnion(newValue)});

我正在使用此版本的Firebase和Firestore

cloud_firestore: ^0.13.7
firebase_storage: ^3.1.6

我尝试按照以下建议运行flutter cleanflutter packages getI/flutter (22027): MissingPluginException(No implementation found for method DocumentReference#setData on channel plugins.flutter.io/cloud_firestore)。正如同一篇文章中所建议的,我什至尝试将multiDexEnabled true添加到我的build.gradle文件中。没有一个起作用。

我注意到我的build.gradle文件具有以下版本:

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

(不知道这是否与问题有关)

请帮助!

谢谢。

1 个答案:

答案 0 :(得分:0)

发现错误与错误消息无关。

问题是我的变量newValue不是列表。我通过更改解决了问题

Firestore.instance.collection('myCollection')
     .document(documentID)
     .updateData({"fieldName": FieldValue.arrayUnion(newValue)});

对此:

Firestore.instance.collection('myCollection')
     .document(documentID)
     .updateData({"fieldName": FieldValue.arrayUnion([newValue])}); //The change is in this line