herbert ichama
herbert ichama

Reputation: 81

Firebase Authentication with Flutter

Flutter Android Firebase authentication Error, The Authentication passes through but error in the terminal although the Application does not fail

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null.

The Error seems to be coming from this Line of code

Future<String> currentUser() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user.uid;
}

Upvotes: 0

Views: 919

Answers (1)

Philip Feldmann
Philip Feldmann

Reputation: 8365

The result of _firebaseAuth.currentUser() was null. Usually that means you are simply not logged in.

Before accessing the current user make sure that you log in. For example using email credentials:

await _firebaseAuth.signInWithEmailAndPassword(email:'[email protected]', password: 'abc123');

The good news is that the firebase package will cache the current user, so after you've logged in you don't have to do it again for a while, you can simply call your currentUser method.

Upvotes: 1

Related Questions