Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Authentication app crashes after creating user

I've been using firebase services for quite some time. So i started a new flutter project yesterday and i'm experiencing app crashes, some times when when a user registers an account With Firebase Auth. according to console log, its probably because of invoking onAuthStateChanged. Can anyone help me resolve this.

NB: Sometimes an account is created successfully without the app crashing.

This is the code where i call onAuthStateChanged :

User _userFromFirebase(FirebaseUser user){
    return user != null ? User(uid: user.uid, email: user.email, name: user.displayName, phoneNo: user.phoneNumber)
        : null ;
  }

  Stream<User> get user {
    return _auth.onAuthStateChanged.map(_userFromFirebase);
  }

Below is the debug console output;

D/FirebaseAuth(14930): Notifying id token listeners about user ( VZcLcnr4dJOZgLjFYU3ls96yHK13 ).
D/FirebaseAuth(14930): Notifying auth state listeners about user ( VZcLcnr4dJOZgLjFYU3ls96yHK13 ).
D/AndroidRuntime(14930): Shutting down VM
E/AndroidRuntime(14930): FATAL EXCEPTION: main
E/AndroidRuntime(14930): Process: com.tonnyapps.app3, PID: 14930
E/AndroidRuntime(14930): java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.invokeMethod(java.lang.String, java.lang.Object)' on a null object reference
E/AndroidRuntime(14930):    at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$3.onAuthStateChanged(FirebaseAuthPlugin.java:710)
E/AndroidRuntime(14930):    at com.google.firebase.auth.zzp.run(com.google.firebase:firebase-auth@@19.2.0:3)
E/AndroidRuntime(14930):    at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime(14930):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(14930):    at com.google.android.gms.internal.firebase_auth.zzj.dispatchMessage(com.google.firebase:firebase-auth@@19.2.0:6)
E/AndroidRuntime(14930):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(14930):    at android.app.ActivityThread.main(ActivityThread.java:7050)
E/AndroidRuntime(14930):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(14930):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/AndroidRuntime(14930):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
I/Process (14930): Sending signal. PID: 14930 SIG: 9
Lost connection to device.
like image 937
Tonny Bawembye Avatar asked Aug 02 '26 18:08

Tonny Bawembye


1 Answers

After many efforts tweaking around with the code and updating dependencies to support higher versions of firebase_auth. I was able to upgrade and fix the version of firebase_auth to version 0.20.1, since it was the last non null-safe version.

And Wallah, it worked, this must have been a bug with whatever version i was using. But it was solved with later releases. The users can now create users successfully and proceed with the normal app flow. So setting firebase_auth: 0.20.1 in the pubspec.yaml, worked for me.

like image 193
Tonny Bawembye Avatar answered Aug 04 '26 09:08

Tonny Bawembye