Home > Mobile >  void Funtion(String) can't be assigned to void Funtion(String?)?
void Funtion(String) can't be assigned to void Funtion(String?)?

Time:12-09

Widget _buildName(){
   return TextFormField(
     decoration: InputDecoration(labelText: "Name"),
     validator: (String value){
       if(value.isEmpty){
         return 'Name is Required';
       }
     },
     onSaved: (String value){
       _name = value;
     }
   );
} 

CodePudding user response:

If you check onSaved and validator methods, both provide nullable string

  • FormFieldSetter<String>? onSaved,
  • FormFieldValidator<String>? validator,

So it will be

TextFormField(
        decoration: InputDecoration(labelText: "Name"),
        validator: (String? value) {
          // add other condition
          if (value == null) {
            return 'Name is Required';
          }
          return null;
        },
        onSaved: (String? value) {
            _name = value; 
        });

More about TextFormField

CodePudding user response:

Kindly add more visual or written details of the bug / issue which you are facing right now so that we can examine and analyze the issue still cant get the exact issue from the provided statement;

  • Related