尝试在颤振中制作输入文本字段,但我无法制作按要求发送函数的验证器函数



这是一个组件文件,我需要帮助:

Widget defaultTextFormField({
required TextEditingController controller,
required TextInputType keyboardtype,
required Function () submitFunction,
required Function validator,
required IconData prefix,
ValueChanged<String>?  onchange,
String labelText =  'Enter Text ...',
}) => TextFormField(
controller: controller,
keyboardType: keyboardtype,
decoration: InputDecoration(
labelText: labelText,
prefixIcon: prefix,
border: OutlineInputBorder(),
),
onFieldSubmitted: submitFunction(),
onChanged: onchange,
validator: validator(),
);

尝试修复我的代码问题。希望能在这方面找到帮助。

validator的定义类似

typedef FormFieldValidator<T> = String? Function(T? value);

它应该返回可为null的数据,并在回调时提供值。你可以使用

required FormFieldValidator validator,

它将与required String Function(String?) validator,相同

并像validator: validator,一样使用

Widget defaultTextFormField({
required TextEditingController controller,
required TextInputType keyboardtype,
required Function(String?) submitFunction,
required FormFieldValidator validator,
required Widget prefix,
ValueChanged<String>? onchange,
String labelText = 'Enter Text ...',
}) =>
TextFormField(
controller: controller,
keyboardType: keyboardtype,
decoration: InputDecoration(
labelText: labelText,
prefixIcon: prefix,
border: OutlineInputBorder(),
),
onFieldSubmitted: submitFunction(),
onChanged: onchange,
validator: validator,
);

相关内容

  • 没有找到相关文章

最新更新