'How to solve Null check operator used on a null value for Signout

'''

const Home({Key? key, required this.onSignOut}) : super(key: key);

  final VoidCallback onSignOut;

  Future<void> _signOut() async {
    try {
      await FirebaseAuth.instance.signOut();
      onSignOut();
    } catch (e) {
      print(e.toString());
    }
    // ignore: avoid_print
  }

  User? _user;
  @override
  void initState() {
    super.initState();
    _updateUser(FirebaseAuth.instance.currentUser!);
  }

  void _updateUser(User user) {
    setState(() {
      _user = user;
    });
  }

  @override
  Widget build(BuildContext context) {
    // ignore: unnecessary_null_comparison
    if (_user == null) {
      return LoginScreen(
        onSignIn: _updateUser,
      );
    }
    return Home(
       onSignOut: (() => _updateUser(null)),//error part 

                                Sign Out is not Working 


[enter image description here][1]
    );
  }

'''

SignOut System is not Working and and doing nothing ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



Solution 1:[1]

             //add this to a button 
             onPressed: (BuildContext context) async {
                setState(() {
                  _isSigningOut = true;
                });
                await FirebaseAuth.instance.signOut();
                setState(() {
                  _isSigningOut = false;
                });
                Navigator.of(context).pushReplacement(
                  MaterialPageRoute(
                    builder: (context) => LoginScreen(),
                  ),
                );
              },

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 alfa