Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

3 errors in make components in flutter

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)?’.

>Solution :

  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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading