During the email app signup process using firebaseAuth.createUserWithEmailAndPassword, when I try to do an upload or save to prefs in the .then part it throws this error: NoSuchMethodError: The getter 'data' was called on null.
So I can work around this by Navigating to a new screen and postponing processing of the user's TextFormField input till there, but it's messy and bugs me.
Doing anything big in the .then seems problematic but I don't really know what's causing the problem, or what in fact the best way is to solve this kind of issue for future clarity. Education appreciated!
void registerToFb() { firebaseAuth .createUserWithEmailAndPassword( email: emailController.text, password: passwordController.text) .then((result) async { Person user = new Person(); user.email = emailController.text; user.firstName = firstNameController.text; user.surname = surnameController.text; user.postcode = postcodeController.text; user.password = passwordController.text; user.city = cityController.text ?? "Edinburgh"; user.firebaseId = result.user.uid; Map<String, dynamic> firebaseUpload = user.toMap(); print("Attempting to reduce upload"); firebaseUpload.removeWhere((key, value) => value == null); user.country = "GB"; String path = "${user.country}/${user.city}/People"; print("Attempting record upload"); DocumentReference autoId = await myFirestore.collection(path).add(firebaseUpload); user.personId = autoId.id; user.saveToPrefs(prefs); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => MyHomePage())); }).catchError((err) { print("Login thrown an error...\n${err.toString()}"); showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text("Error 10"), content: Text("${err.toString()}"), actions: [ ElevatedButton( child: Text("Ok"), onPressed: () { Navigator.of(context).pop(); }, ) ], ); }); });