0

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),
      ),
    ),
1
  • 1
    ! is used when you are sure its not null. You have to either check the value is null or not before using the ! operator or use ? operator Commented Jan 2, 2023 at 10:29

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Null text is displayed in place of the email id.
that's indicates the instance of firebaseAuth is not able to fetch the data of currentUser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.