Hassani Chamseddine
Hassani Chamseddine

Reputation: 1

error: The argument type 'dynamic Function()?'

// error: The argument type 'dynamic Function()?' can't be assigned to the parameter type 'String? Function(String?)?'. (argument_type_not_assignable at [firsfapp] lib/shared/components/components.dart:42)

Widget defaultButton({
  double width = double.infinity,
  Color background = Colors.blue,
  @required void Function()? function,
  @required String? text,
  bool isUpperCase = true,
  double radius = 65.0,
}) => Container(
  width: width,
  height: 40.0,
  child: MaterialButton(
    onPressed: function,
    child: Text(
      isUpperCase ? text!.toUpperCase() : text!,
      style: TextStyle(
        color: Colors.white,
      ),
    ),
  ),
  decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(
    radius,
    ),
    color: background,
  ),
);

Widget dfailtFormField({
  @required TextEditingController? controller,
  @required TextInputType? type,
   Function(String)? onSubmit,
   Function(String)? onChange,
   Function()? validate,
}) => TextFormField(
  controller: controller,
  keyboardType: type,
  onFieldSubmitted: onSubmit,
  onChanged: onChange,
  validator: validate,
  decoration: InputDecoration(
    labelText: 'Email Address',
    border: OutlineInputBorder(),
    prefixIcon: Icon(
      Icons.email,
    ),
  ) ,
);

Upvotes: 0

Views: 479

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63614

The validator needs null-able callback String method, It is defined as

String? Function(T? value)

You can convert your validate like

String? Function(String?)? validate,

I am using null-safety.

Upvotes: 1

Related Questions