我正在尝试更新文档并不断出现此错误:
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 clean
和flutter packages get
:I/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'
}
(不知道这是否与问题有关)
请帮助!
谢谢。
答案 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