错误:参数类型为"动态函数()?



//错误:参数类型为'dynamic Function()?'不能分配给参数类型'字符串?字符串函数(?)吗?"。(argument_type_not_assignable at [firstapp] 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,
),
) ,
);

validator需要可为空的回调字符串方法,定义为

String? Function(T? value)

您可以将您的validate转换为

String? Function(String?)? validate,

我正在使用null-safety

最新更新