我试图将数据添加到Firestore中,但是“ Firestore组件不存在”。终端给出此错误消息

时间:2019-04-29 18:13:43

标签: dart flutter google-cloud-firestore

我正在尝试将数据写入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 / flutter(18061):[错误:flutter / lib / ui / ui_dart_state.cc(148)]   未处理的异常:PlatformException(错误,Firestore组件为   不存在。,null)E / flutter(18061):#0
  StandardMethodCodec.decodeEnvelope   (package:flutter / src / services / message_codecs.dart:564:7)E / flutter   (18061):#1 MethodChannel.invokeMethod   (package:flutter / src / services / platform_channel.dart:302:33)E / flutter   (18061):E / flutter(18061):#2
  DocumentReference.setData   (文件:///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   (文件:///home/mamba/Software/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.10.0/lib/src/collection_reference.dart:58:23)   E / flutter(18061):E / flutter(18061):#4
  _addNewMemberState.createData(package:teamapp / Pages / addNewMember.dart:218:61)E / flutter(18061):    E / flutter(18061):#5
  _InkResponseState._handleTap(包: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(包:flutter / src / gestures / recognizer.dart:120:24)E / flutter   (18061):#8 TapGestureRecognizer._checkUp   (包装:flutter / src / gestures / tap.dart:242:9)E / flutter(18061):#9
  TapGestureRecognizer.acceptGesture   (包装: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(软件包: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 / flutter(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 个答案:

答案 0 :(得分:0)

喜欢这个。 删除android和ios目录,然后运行“ flutter create” https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#generated-project-files-outdated