Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This function has a return type of 'String', but doesn't end with a return statement

Tags:

flutter

dart

I got stuck with an error can anyone help me to solve this "This function has a return type of 'String' but doesn't end with a return statement. Try adding a return statement, or changing the return type to 'void'.",

Under value it is underlined with the blue line(showing error)

TextFormField(
              decoration: InputDecoration(labelText: 'E-Mail'),
              keyboardType: TextInputType.emailAddress,
              validator: (value) {
                if (value.isEmpty || !value.contains('@')) {
                  return 'Invalid email!';
                }
              },
              onSaved: (value) {
                _authData['email'] = value;
              },
           ),
like image 986
smily g1908 Avatar asked Sep 07 '25 00:09

smily g1908


1 Answers

You forgot to return null
code snippet

validator: (value) {
            if (value.isEmpty || !value.contains('@')) {
              return 'Invalid email!';
            }
            return null;
          },
like image 58
chunhunghan Avatar answered Sep 10 '25 13:09

chunhunghan