(Flutter) Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't

259
void signin() async { 
   await FirebaseAuth.instance .signInWithEmailAndPassword(
      email: _email! /* <-- */, 
      password: _password! /* <-- */).catchError((onError) {
        print(onError);
      }).then((authUser) => print(authUser.user?.uid));
}

try to add null(!)

Share:
259
Sivaselan Raj
Author by

Sivaselan Raj

Updated on November 26, 2022

Comments

  • Sivaselan Raj
    Sivaselan Raj over 1 year

    im using flutter in android studio. coding as below.

    class _loginscreenState extends State<loginscreen> {
      GlobalKey<FormState> formKey = GlobalKey<FormState>();
    
      String? _email, _password;
    
      void signin() async {
        await FirebaseAuth.instance
            .signInWithEmailAndPassword(email: _email, password: _password)
            .catchError((onError) {
          print(onError);
        }).then((authUser) => {print(authUser.user?.uid)});
      }
    

    please help me to solve this why the code cant run and what is the meaning of "'String?' is nullable and 'String' isn't". and what is the solution?

  • Community
    Community about 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.