Home > Software design >  type 'Null' is not a subtype of type 'String'
type 'Null' is not a subtype of type 'String'

Time:12-20

i am getting this error in login fuction

void _login() async {
  var user = LoginUser(
    emailId: _emailController.text,
    password: _passwordController.text,
  );

  try {
    CustomerLoginResponse response =
        await ApiManager().loginUser(user).catchError((err) {
      return Future<CustomerLoginResponse>.error(err);
    });

    if (response.successful) {
      showDataAlert();
      print(response.message);
    } else {
      print(response.message);
    }
  } catch (e) {
    print(e);
  }
}

error i am getting : I/flutter ( 5362): type 'Null' is not a subtype of type 'String'

CodePudding user response:

This error message typically indicates that you are trying to assign a value of type Null to a variable or field that expects a value of type String.

To fix this error, you will need to make sure that the value you are trying to assign to a variable or field is of the correct type. If you want to allow for the possibility of the deal being null, you can use the '?' operator to specify that the variable or field is nullable,

CodePudding user response:

I'll bet your emailController or passwordController are null. it's not passing the text from your TextField entries to _login. You have to assign the controller value for each. Can't really say for certain, but I'd start there. It's always helpful to let us know the exact line that is giving you the error.

  • Related