I have created a custom TextFormField as the following:

class NoteFormField extends StatelessWidget {
  const NoteFormField({  // <------ No.1
    this.key,
    this.controller,
    this.autofocus = false,
    this.hintText,
    this.validator,
    this.onChanged,
  });

  final Key? key;   // <------- No.2
  final TextEditingController? controller;
  final bool autofocus;
  final String? hintText;
  final String? Function(String?)? validator;
  final void Function(String)? onChanged;

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      key: key,
      controller: controller,
      autofocus: autofocus,
      decoration: InputDecoration(
        hintText: hintText,
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: primary),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: primary),
        ),
        errorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: Colors.red),
        ),
        focusedErrorBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(8),
          borderSide: const BorderSide(color: Colors.red),
        ),
        contentPadding: const EdgeInsets.symmetric(horizontal: 8),
      ),
      validator: validator,
      onChanged: onChanged,
    );
  }
}

It gives me the following lint messages, based on the numbering that I have labelled in the code:

  1. Constructors for public widgets should have a named 'key' parameter. Try adding a named parameter to the constructor.
  2. The member 'key' overrides an inherited member but isn't annotated with '@override'. Try adding the '@override' annotation.dartannotate_overrides Field overrides a field inherited from 'Widget'. Try removing the field, overriding the getter and setter if necessary.dartoverridden_fields
0

There are 0 best solutions below