I tried to add the user's data in Firestore while creating the user by 'createUserWithEmailAndPassword'. After submitting the button it not directed to the next page but the user is added in the Firebase authentication but not in the Firestore collection.

Below is the code used to add the user:

`auth.createUserWithEmailAndPassword(_email, _password, _name).then((value){
FirebaseFirestore.instance.collection('users').doc().set({
"email" : _email,
"userName" : _name,}).then((res)
{Navigator.of(context).pushReplacementNamed('/home');});});`

Error:

W/System  (30919): Ignoring header X-Firebase-Locale because its value was null.
W/System  (30919): Ignoring header X-Firebase-Locale because its value was null.
D/FirebaseAuth(30919): Notifying id token listeners about user ( qsKxr5mobGc44D8poFIINgZbLCK2 ).
D/FirebaseAuth(30919): Notifying auth state listeners about user ( qsKxr5mobGc44D8poFIINgZbLCK2 ).
E/flutter (30919): [ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: NoSuchMethodError: Class '_TypeError' has no instance getter 'message'.
E/flutter (30919): Receiver: Instance of '_TypeError'
E/flutter (30919): Tried calling: message
E/flutter (30919): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (30919): #1      _SignUpViewState.submit.<anonymous closure> (package:madrasdaily/sign_up_page.dart:84:24)
E/flutter (30919): #2      State.setState (package:flutter/src/widgets/framework.dart:1244:30)
E/flutter (30919): #3      _SignUpViewState.submit (package:madrasdaily/sign_up_page.dart:83:9)
E/flutter (30919): <asynchronous suspension>
E/flutter (30919): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:19)
E/flutter (30919): #5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter (30919): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (30919): #7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:523:11)
E/flutter (30919): #8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:283:5)
E/flutter (30919): #9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:218:7)
E/flutter (30919): #10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter (30919): #11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter (30919): #12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (30919): #13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (30919): #14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (30919): #15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (30919): #16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:219:19)
E/flutter (30919): #17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
E/flutter (30919): #18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:157:7)
E/flutter (30919): #19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:103:7)
E/flutter (30919): #20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:87:7)
E/flutter (30919): #21     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (30919): #22     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30919): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30919): #24     _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter (30919): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
E/flutter (30919): 

Flutter doctor:

[email protected] madrasdaily % flutter doctor -v
[✓] Flutter (Channel master, 1.22.0, on Mac OS X 10.15.5 19F101, locale en-GB)
    • Flutter version 1.22.0 at /Users/elamparithi/Developer/flutter
    • Framework revision d261f1ef58 (4 months ago), 2020-08-03 00:59:36 -0400
    • Engine revision 083282e33b
    • Dart version 2.10.0 (build 2.10.0-4.0.dev 365525432a)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/elamparithi/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (3 available)
    • AOSP on IA Emulator (mobile) • emulator-5554 • android-x86    • Android 9 (API 28) (emulator)
    • Web Server (web)             • web-server    • web-javascript • Flutter Tools
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 86.0.4240.198

• No issues found!


Solution 1: marian.vladoi

Please check this similar SO question:

Firebase Authentication creates user but does not add their Info to database

They are recommending to add print statement in your code to check the error message.

Also you should check the security rules because this might solve your issue.