user11378426
user11378426

Reputation:

Flutter Firebase Error Null fundtion(FirebaseUser) cant assigned to parame,meter type FutureOr<dynamic>

In my Firebase Authentication im am facing the Error:

error: The argument type 'Null Function(FirebaseUser)' can't be assigned to the parameter type 'FutureOr Function(AuthResult)'. (argument_type_not_assignable at [authentication] lib\loginpage.dart:44)

if importet firebase_auth and flutter material

            onPressed: (){
              FirebaseAuth
              .instance
                  .signInWithEmailAndPassword(
                email: _email,
                password: _password
              ).then((FirebaseUser user){
                Navigator.of(context).pushReplacementNamed('/homepage');
              })
                  .catchError((e){
                    print(e);
              });
            }

Upvotes: 1

Views: 2243

Answers (2)

karthikeyan G
karthikeyan G

Reputation: 11

onPressed: () {
                  FirebaseAuth.instance
                      .signInWithEmailAndPassword(
                          email: _email, password: _password)
                      .then((value) {
                    Navigator.of(context).pushReplacementNamed('/homepage');
                  }).catchError((e) {
                    print(e);
                  });
                },

try this it will work. if you have multidex error then refer this link https://developer.android.com/studio/build/multidex#java

Upvotes: 0

Gianluca Cesari
Gianluca Cesari

Reputation: 36

Looking at the source code of the plugin the function

.signInWithEmailAndPassword()

is a Future which return an AuthResult, so the problem is in your callback method

.then((FirebaseUser user)

should instead be

.then((AuthResult auth)

You can see it here

Upvotes: 3

Related Questions