Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Null check operator used on a null value in flutter project

In the drawer, I’m showing the user’s email address. but null error is showing !
i am also adding ? this sign same error but null

final email = FirebaseAuth.instance.currentUser!.email;


   Center(
      child: Text(
        '$email',
        style: const TextStyle(fontWeight:   FontWeight.bold, fontSize: 18.0, color: Colors.indigo),
      ),
    ),

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It is possible your currentUser is null. Instead of forcing with bang!, you can do a null check or accept null value like

final email = FirebaseAuth.instance.currentUser?.email;

Also you can provide default value like

final email = FirebaseAuth.instance.currentUser?.email ?? "Got null user";

Find more about null-safety

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading