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?
5
Answers
try to add null(!)
Here you must supply email and password.if it was String?. may or maynot it contain null value .so Avoiding that
email.tostring()
we can usetostring()
.if email is a null value it will converted to "Null" after addingemail.toString()
.this is caused by using sound null safety in your app
and you are passing a nullable string to a non-nullable string
some solutions are:
for more elaboration on thisstring is null and string isnt
or how to resolve argument type string…
You have made
String? _email, _password;
email and password nullable.after that you haven’t initialized the value of email and password. and you are directly using email and password inside
FirebaseAuth.instance.signInWithEmailAndPassword
which does not support null values.Try initializing the value of email and password.
You can use TextEditingController if you are fetching value from textfield. and pass the value of email and password as parameter.
Then use this function.