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’
2
Answers
If you’re only get the error when credentials are wrong, then LoginUser is returning null and it’s expecting a string. I would declare user as
String? user = LoginUser
… Again, all this is somewhat inference because you’re not providing full info to know for sure. Then you need to null check user. User an if/then to ensure thatif (user != null)....
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,