Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in day8 code #43

Open
Shivansh-yadav13 opened this issue Feb 25, 2023 · 4 comments
Open

Error in day8 code #43

Shivansh-yadav13 opened this issue Feb 25, 2023 · 4 comments

Comments

@Shivansh-yadav13
Copy link

if (value.isEmpty) {

This does not work anymore, it gives an error

The property 'isEmpty' can't be unconditionally accessed because the receiver can be 'null'. 

Similarly,

if (_formKey.currentState.validate()) {

This also give error

The method 'validate' can't be unconditionally invoked because the receiver can be 'null'. 
@lazysquid7
Copy link

Did you find any alternative how to do it?

@lazysquid7
Copy link

value.isEmpty can be replaced with =>> value == null / value.isNull
But how to resolve other issue?

@lazysquid7
Copy link

Use below code to resolve the issue.
If you are getting an error in the TextFormField validator, your condition should be :
validator: (value) {
if (value ==null || value.isEmpty) {
return "Username cannot be empty";
}

Similar in both username and password.

And in the moveToHome() method validation condition should be:
if(_formkey.currentState!.validate()){};

@malik-vishu
Copy link

`validator: (value) {
if (value != null && value.isEmpty) {
return "Username cannot be empty";
}

  return null;

}`

`moveToHome(BuildContext context) async {
if (formKey.currentState != null && formKey.currentState!.validate()) {
setState(() {
change = true;
});

  await Future.delayed(const Duration(seconds: 1));
  await Navigator.pushNamed(context, AllRoutes.homeRoute);
  setState(() {
    //rendering again on coming back
    change = false;
  });
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants