当我试图从FireStore中读取数据时,它会显示错误。[错误:flutter/lib/ui/ui_dart_state.cc(157)]未处理的异常:PlatformException(错误,无效的文档引用。文档引用必须有偶数个段,但users有1,null)代码为:
bool hasData = false;
String number;
var val;
final usersRef = Firestore.instance.collection('users');
@override
void initState() {
this.number = '';
FirebaseAuth.instance.currentUser().then((value) {
setState(() {
val = value;
this.number = value.phoneNumber;
});
}).catchError((e) {
print(e);
});
checkData();
super.initState();
}
checkData() async {
DocumentSnapshot doc = await usersRef.document(this.number).get();
if (doc.exists) {
setState(() {
hasData = true;
});
} else {
setState(() {
hasData = false;
});
}
}
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): Failed to handle method call
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): java.lang.IllegalArgumentException: Invalid document reference. Document references must have an even number of segments, but users has 1
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at com.google.firebase.firestore.DocumentReference.forPath(com.google.firebase:firebase-firestore@@21.3.0:80)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at com.google.firebase.firestore.FirebaseFirestore.document(com.google.firebase:firebase-firestore@@21.3.0:249)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getDocumentReference(CloudFirestorePlugin.java:115)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:890)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at android.app.ActivityThread.main(ActivityThread.java:6762)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#plugins.flutter.io/cloud_firestore( 4166): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter ( 4166): **[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Invalid document reference. Document references must have an even number of segments, but users has 1, null)**
E/flutter ( 4166): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 4166): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter ( 4166): <asynchronous suspension>
E/flutter ( 4166): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter ( 4166): #3 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:356:48)
E/flutter ( 4166): #4 MethodChannelDocumentReference.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:56:46)
E/flutter ( 4166): #5 DocumentReference.get (package:cloud_firestore/src/document_reference.dart:69:47)
E/flutter ( 4166): #6 _CreateUserState.checkData (package:knowledgehub/createuser.dart:36:65)
E/flutter ( 4166): #7 _CreateUserState.initState (package:knowledgehub/createuser.dart:31:5)
E/flutter ( 4166): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4640:58)
E/flutter ( 4166): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4166): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4166): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:3211:20)
E/flutter ( 4166): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4166): #13 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter ( 4166): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4166): #15 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
E/flutter ( 4166): #16 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:20)
E/flutter ( 4166): #17 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
E/flutter ( 4166): #18 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
E/flutter ( 4166): #19 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
E/flutter ( 4166): #20 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:968:5)
E/flutter ( 4166): #21 _rootRun (dart:async/zone.dart:1184:13)
E/flutter ( 4166): #22 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter ( 4166): #23 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter ( 4166): #24 _invoke (dart:ui/hooks.dart:261:10)
E/flutter ( 4166): #25 _drawFrame (dart:ui/hooks.dart:219:3)
E/flutter ( 4166):
I/flutter ( 4166): +91xxxxxxxxxx
W/IInputConnectionWrapper( 4166): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 4166): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 4166): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 4166): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 4166): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 4166): getTextAfterCursor on inactive InputConnection
I/flutter ( 4166): Suraj Jha
W/co.knowledgehu( 4166): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
W/co.knowledgehu( 4166): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/co.knowledgehu( 4166): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
W/co.knowledgehu( 4166): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
I/flutter ( 4166): Instance of 'User'
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/CloseGuard;->close()V (light greylist, linking)
W/co.knowledgehu( 4166): Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, linking)
您的变量数没有任何有效值,它只是一个空的字符串
。因为您使用的是。然后
将直接调用checkdata()
函数,而无需等待分配数字。而不是使用。然后
可以使用await
var result = await FirebaseAuth.instance.currentUser();
number = result.phoneNumber;
checkData();
我希望这能有所帮助。
[错误:flutter/lib/ui/ui_dart_state.cc(157)]未处理的异常:PlatformException(错误,文档引用无效。文档引用的段数必须为偶数,但users为1,为null)
WARN[WrapperSimpleAppMain][XmlBeanDefinitionReader]忽略XML验证警告org.XML.sax.SAXParseException;行号:14;列号:80;schemaLocation:schemaLocation值='http://www.springfr amework.org/schema/beans http://www.springfram
我知道这个主题在这里讨论了很多次,但我仍然坚持一个例外:外键必须与引用的主键具有相同的列数。 (我正在使用spring数据和hibernate) 我的身份证类别: 我的实体: 对于这种构造,我得到以下例外情况: 导致:org.hibernate.MappingException:外键(FK_ad3h9gu4labg6ix34bei3poxt:proxy_dienst_关系[parent_diens
嗨,我正在创建一个简单的注册表单与django框架和mongodb。以下是我的观点: 以下是我的模型: 下面是我的<code>表单。py</code> 以下是加载 SignUpview 回溯时收到的回溯值错误: 内部 39 中的文件“C:\程序文件\Python35\lib\site-packages\django\core\处理程序\exception.py”。响应 = get_response
本文向大家介绍你必须掌握在Flutter中添加资源文件的方法,包括了你必须掌握在Flutter中添加资源文件的方法的使用技巧和注意事项,需要的朋友参考一下 在 Flutter 中,需要在根目录下的 pubspec.yaml 文件中配置资源的路径,资源才能被打包使用。现在,看看如何配置资源吧。 1. 添加图片资源文件 1.1 添加本地图片资源 注意缩进!本地文件夹内的资源可以选择导入整个文件夹,或者
Flutter 来自 Google 免费开源的项目,提供了通过一套代码同时构建 iOS 和 Android 漂亮的原生应用能力。