1

I'm trying to delete a FirebaseUser, and It returns a null error. I dunno what's wrong with my code.
can somebody answer with a proper explanation cause I'm new to this error!

The error:

D/FirebaseAuth(16061): Notifying id token listeners about user ( r6Nn5Gxxxxxxxxxxxxxxx ).
I/flutter (16061): Deletion error NoSuchMethodError: The method '[]' was called on null.
I/flutter (16061): Receiver: null
I/flutter (16061): Tried calling: []("user")

Here's how I'm trying to delete the user:

 new FlatButton(
                child: Text("Delete"),
                onPressed: () async {
                  if (password.text.length == 0) {
                    showInSnackBar("Please enter your password");
                  } else {
                    FirebaseUser firebaseUser =
                        await FirebaseAuth.instance.currentUser();
                    String uid = firebaseUser.uid;
                      var credential = EmailAuthProvider.getCredential(
                          email: firebaseUser.email,
                          password: password.text);
                      var result = await firebaseUser
                          .reauthenticateWithCredential(credential);

                    try {
                      await result.user.delete();
                    } on PlatformException catch (e) {
                      print("///////// ${e.code}");
                      String errorCde = e.code;
                      if (errorCde == "ERROR_WRONG_PASSWORD") {
                        showInSnackBar("Wrong password! Please try agian.");
                      } else if (errorCde == "ERROR_TOO_MANY_REQUESTS") {
                        showInSnackBar(
                            "You've tried too many times, Please try again in a while!");
                      } else if (errorCde ==
                          "ERROR_NETWORK_REQUEST_FAILED") {
                        showInSnackBar(
                            "Please check your internet connection");
                      }
                    } catch (e) {
                      print("Deletion error $e");
                      showInSnackBar("Something went wrong");
                    }
                  }
                },
              ),
Pranav
  • 411
  • 6
  • 19
  • 2
    Are your Firebase packages all the latest versions? There was a bug that caused this but that was at the end of last year. See: https://github.com/FirebaseExtended/flutterfire/issues/1085 – GrahamD Jul 20 '20 at 15:45
  • Yeah, every packages are on the latest, I've double-checked them. – Pranav Jul 20 '20 at 15:54
  • Maybe try using the method here https://stackoverflow.com/questions/37811684/how-to-create-credential-object-needed-by-firebase-web-user-reauthenticatewith instead of getCredential I would change the delete() line with firebase.auth().currentUser().delete() or something similar – ProfessorManhattan Jul 21 '20 at 04:24

0 Answers0