0

I have 3 errors I tried all possible solutions
look at this

Widget defaultFormField ({
  @required TextEditingController? controller,
  @required TextInputType? keyboardType,
  @required IconData? prefix,
  @required String? label,
  VoidCallback? onChange,
  @required VoidCallback? validate,

}) => TextFormField(
    style: const TextStyle(
      color: Colors.amber,
    ),
    cursorHeight: 25.0,
    cursorColor: Colors.amber,
    controller: controller,
    keyboardType: keyboardType,
    decoration: const InputDecoration(
      prefixIcon: Icon(Icons.person_outline),
      labelText: label,
      labelStyle: TextStyle(
        color: Colors.amber,
      ),
      border: OutlineInputBorder(),
      enabledBorder: OutlineInputBorder(
        borderSide: BorderSide(
            color: Colors.amber
        ),
      ),
      focusedBorder: OutlineInputBorder(
        borderSide: BorderSide(
          color: Colors.amber,
        ),
      ),
    ),
    onChanged: onChange,
    validator : validate,
);

these are problems

Invalid constant value.

The argument type 'void Function()?' can't be assigned to the parameter type 'void Function(String)?'.

The argument type 'void Function()?' can't be assigned to the parameter type 'void Function(String)?'.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
basel elazaly
  • 39
  • 1
  • 5

2 Answers2

1
  1. remove const from this line decoration: const InputDecoration( .

  2. required Function? onChange,

  3. required Function? validator,

use onChanged like this

 onChanged: (value) {
         return onChanged != null ? onChanged(value) : null;
  },

use validator like this

validator: (value) {
            return validator != null ? validator(value) : null;
          },

try above code it can solve your error. and remove @ from required.

Ravin Laheri
  • 801
  • 3
  • 11
0

onChanged provide string on callback, do it like

Function(String)? onChange,

Also for validator it can be

 required Function(String?) validate,

validator : (value) =>  validate(value),

defaultFormField method

 Widget defaultFormField({
    required TextEditingController? controller,
    required TextInputType? keyboardType,
    required IconData? prefix,
    required String? label,
    Function(String)? onChange,
    required Function(String?) validate,
  }) =>
      TextFormField(
        style: const TextStyle(
          color: Colors.amber,
        ),
        cursorHeight: 25.0,
        cursorColor: Colors.amber,
        controller: controller,
        keyboardType: keyboardType,
        decoration: InputDecoration(
          prefixIcon: Icon(Icons.person_outline),
          labelText: label,
          labelStyle: TextStyle(
            color: Colors.amber,
          ),
          border: OutlineInputBorder(),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(color: Colors.amber),
          ),
          focusedBorder: OutlineInputBorder(
            borderSide: BorderSide(
              color: Colors.amber,
            ),
          ),
        ),
        onChanged: onChange,
        validator: (value) => validate(value),
      );
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56