I am getting argument type not assignable error in dart while checking the email value is empty or not the error which I am getting are
The argument type
void Function(String)
can't be assigned to the parameter typevoid Function(String?)?
.
and
The argument type
String? Function(String)
can't be assigned to the parameter type'String? Function(String?)?
.
These are the validator classes,
class EmailFieldValidator {
static String? validate(String value) {
return value.isEmpty ? 'Email can\'t be empty' : null;
}
}
class PasswordFieldValidator {
static String? validate(String value) {
return value.isEmpty ? 'Password can\'t be empty' : null;
}
}
Here is the code giving the error
List<Widget> buildInputs() {
return <Widget>[
TextFormField(
key: Key('email'),
decoration: InputDecoration(labelText: 'Email'),
validator: EmailFieldValidator.validate, //this gives string error mentioned above
onSaved: (String value) => _email = value, //getting void error mention above
),
TextFormField(
key: Key('password'),
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
validator: PasswordFieldValidator.validate, // getting string error mentioned above
onSaved: (String value) => _password = value, //getting void error mention above
),
];
}