0
votes

I'm trying to write data to firestore.

I tried solutions on other questions. but could not solve the problem. Here is the terminal output and createData function.

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/flutter (18061): * I/flutter (18061): ** I/flutter (18061): *** E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): Failed to handle method call E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): java.lang.NullPointerException: Firestore component is not present. E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:906) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@18.2.0:88) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@18.2.0:80) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getFirestore(CloudFirestorePlugin.java:82) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getDocumentReference(CloudFirestorePlugin.java:92) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:533) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at android.os.Looper.loop(Looper.java:135) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at android.app.ActivityThread.main(ActivityThread.java:7331) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) E/MethodChannel#plugins.flutter.io/cloud_firestore(18061): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) E/flutter (18061): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Firestore component is not present., 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 (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/flutter (18061): E/flutter (18061): #4
_addNewMemberState.createData (package:teamapp/Pages/addNewMember.dart:218:61) E/flutter (18061): E/flutter (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/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

1 Answers

1
votes

solved by this, refer to the GitHub link. delete android and ios directories then run "flutter create" https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#generated-project-files-outdated