Home > Blockchain >  The argument type 'void Function(User)' can't be assigned to the parameter type '
The argument type 'void Function(User)' can't be assigned to the parameter type '

Time:03-19

How can I fix this error: The argument type 'void Function(User)' can't be assigned to the parameter type 'void Function(User?)?'. enter image description here

instance.authStateChanges().listen((User user) {
      if(user == null){
        //print('no user');
        Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context) => Login()));
      }else {
        //print('there is a user');
      }
    });

CodePudding user response:

change the argument user to (User? user)

so the code would be:

instance.authStateChanges().listen((User? user) {
      if(user == null){
        //print('no user');
        Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context) => Login()));
      }else {
        //print('there is a user');
      }
    });

CodePudding user response:

Try like this:

instance.authStateChanges().listen((user) {
      if(user == null){
        //print('no user');
        Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context) => Login()));
      }else {
        //print('there is a user');
      }
    });
  • Related