我正在尝试制作一个Flutter应用程序,在其中收集一些学生数据并将其存储到Firestore中。我想在有关用户的集合中添加有关用户的文档,并在具有自定义ID(例如uid)的内部文档中添加
。我面临的问题是我无法在这样的文档上设置数据,该文档既没有特定的文档,也没有集合。现在,这实际上不是问题的原因,因为在将JavaScript库用于云存储时可以使用。
我的依赖项:
dependencies:
flutter:
sdk: flutter
google_sign_in: ^4.0.1+1
scoped_model: ^1.0.1
http: ^0.12.0+1
shared_preferences: ^0.4.2
rxdart: ^0.20.0
file_picker: ^1.2.0
flutter_pdf_viewer: ^0.2.0
firebase_auth: ^0.8.1+4
firebase_core: ^0.3.1+1
firebase_messaging: ^4.0.0+1
firebase_storage: ^2.1.0+1
cloud_firestore: ^0.9.5+2
到目前为止的代码:
Future<bool> storeStudentData(Map<String, Object> data) async {
String uid = authenticatedUser.id;
DocumentReference docRef = db.collection('users').document(uid);
try {
await docRef.setData(data);
print('Done setting data');
return true;
} catch (err) {
print('EERRRR setting data');
return false;
}
}
我的Firestore规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
我面临的错误
[ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)]
java.lang.NoSuchMethodError: No virtual method
set(Ljava/util/Map;)Lcom/google/android/gms/tasks/Task; in class
Lcom/google/firebase/firestore/DocumentReference; or its super classes
(declaration of 'com.google.firebase.firestore.DocumentReference' appears in
/data/app/com.example.rla_official-1/base.apk:classes2.dex)
E/flutter (24452): at
io.flutter.plugins.firebase.cloudfirestore.
CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:523)
E/flutter (24452): at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler
.onMessage(MethodChannel.java:201)
E/flutter (24452): at
io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl
.handleMessageFromDart(FlutterNativeView.java:188)
E/flutter (24452): at io.flutter.embedding.engine.FlutterJNI.
handlePlatformMessage(FlutterJNI.java:202)
E/flutter (24452): at android.os.MessageQueue.nativePollOnce(Native
Method)
E/flutter (24452): at
android.os.MessageQueue.next(MessageQueue.java:328)
E/flutter (24452): at android.os.Looper.loop(Looper.java:148)
E/flutter (24452): at
android.app.ActivityThread.main(ActivityThread.java:6339)
E/flutter (24452): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (24452): at
com.android.internal.os.
ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
E/flutter (24452): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
E/flutter (24452):
F/flutter (24452):
[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)]
Check failed: CheckException(env).
F/libc (24452): Fatal signal 6 (SIGABRT), code -6 in tid 24452
(le.rla_official)
Lost connection to device.
请注意,我可以从Firestore中读取数据。那里没有错误。因此,安全规则也不是问题。 另外,运行该功能时,集合用户,因此其中没有文档。
我在其他一些android(java)项目中进行了尝试,并且可以正常工作。
我需要能够为文档提供自定义ID,以便以后高效检索。