我试图向 Firestore 添加数据,但“Firestore 组件不存在”。终端给出这个错误信息

Posted

技术标签:

【中文标题】我试图向 Firestore 添加数据,但“Firestore 组件不存在”。终端给出这个错误信息【英文标题】:I was trying to add data to firestore but, "Firestore component is not present." terminal gives this error message 【发布时间】:2019-09-18 09:30:43 【问题描述】:

我正在尝试将数据写入 Firestore。

我尝试了其他问题的解决方案。但无法解决问题。 这是终端输出和createData函数。

void createData() async 
  print("*");
if (_formKey.currentState.validate()) 
  print("**");
  _formKey.currentState.save();
  print("***");
  DocumentReference ref = await db.collection('member').add('Index': _indexNo, 'NIC': _nicNo,'Name':_name,'Faculty': _faculty,'Year':_year,'Telephone':_telephone);
  setState(() => id = ref.documentID);
  print(ref.documentID);
  print('done');


I/颤动 (18061): * I/颤动 (18061): ** I/颤动 (18061): *** E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): 失败 处理方法调用 E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): java.lang.NullPointerException:Firestore 组件不存在。 E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 com.google.common.base.Preconditions.checkNotNull(Preconditions.java:906) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@18.2.0:88) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@18.2.0:80) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getFirestore(CloudFirestorePlugin.java:82) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getDocumentReference(CloudFirestorePlugin.java:92) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:533) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 android.os.MessageQueue.nativePollOnce(本机方法) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 android.os.Looper.loop(Looper.java:135) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 android.app.ActivityThread.main(ActivityThread.java:7331) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 java.lang.reflect.Method.invoke(本机方法) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) E/颤振(18061):[错误:颤振/lib/ui/ui_dart_state.cc(148)] 未处理的异常:PlatformException(错误,Firestore 组件是 不存在。,空)E/颤振(18061):#0 StandardMethodCodec.decodeEnvelope (包:flutter/src/services/message_codecs.dart:564:7) E/flutter (18061): #1 MethodChannel.invokeMethod (包:flutter/src/services/platform_channel.dart:302:33) E/flutter (18061): E/颤振 (18061): #2 DocumentReference.setData (file:///home/mamba/Software/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.10.0/lib/src/document_reference.dart:43:30) E/flutter (18061):#3 CollectionReference.add (file:///home/mamba/Software/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.10.0/lib/src/collection_reference.dart:58:23) E/颤动​​ (18061): E/颤动 (18061): #4 _addNewMemberState.createData (package:teamapp/Pages/addNewMember.dart:218:61) E/flutter (18061): E/颤振 (18061):#5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14) E/flutter (18061):

#6 _InkResponseState.build。 (package:flutter/src/material/ink_well.dart:568:30) E/flutter (18061):

#7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:120:24) E/flutter (18061):#8 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9) E/flutter (18061): #9 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7) E/flutter (18061): #10 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27) E/flutter (18061):

#11 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:20) E/flutter (18061):

#12 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22) E/flutter (18061):

#13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7) E/flutter (18061):

#14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7) E/flutter (18061):

#15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7) E/flutter (18061):

#16 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter (18061): #17 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/颤振(18061):#18 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter (18061): #19 _invoke1 (dart:ui/hooks.dart:223:10) E/flutter (18061): #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5)

【问题讨论】:

【参考方案1】:

由此解决,参考GitHub链接。 删除 android 和 ios 目录然后运行“flutter create” https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#generated-project-files-outdated

【讨论】:

以上是关于我试图向 Firestore 添加数据,但“Firestore 组件不存在”。终端给出这个错误信息的主要内容,如果未能解决你的问题,请参考以下文章

如何继续向现有 Firestore 查询添加条件?

循环将文档添加到 Google Firestore

在 Flutter 中捕获云 Firestore 文档快照错误

如何在 firestore 中的现有数组中添加或删除项目?

无法在 Firestore 模拟器上写入

Firestore 更改后使用 FCM 发送推送通知? [复制]