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

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');
      }
    });


Solution 1:[1]

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');
      }
    });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tareq albeesh