diff --git a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart index b1f8a88e..9e5f095f 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart @@ -17,10 +17,12 @@ class MiraiTextFormFieldParser extends MiraiParser { const MiraiTextFormFieldParser({ this.controler, this.onChange, + this.validator, }); final TextEditingController? controler; final Function(String value)? onChange; + final String? Function(String?)? validator; @override MiraiTextFormField getModel(Map json) => @@ -35,6 +37,7 @@ class MiraiTextFormFieldParser extends MiraiParser { model: model, controler: controler, onChange: onChange, + validator: validator, ); } } @@ -44,11 +47,13 @@ class _TextFormFieldWidget extends StatefulWidget { required this.model, this.controler, this.onChange, + this.validator, }); final MiraiTextFormField model; final TextEditingController? controler; final Function(String value)? onChange; + final String? Function(String?)? validator; @override State<_TextFormFieldWidget> createState() => _TextFormFieldWidgetState(); @@ -117,20 +122,15 @@ class _TextFormFieldWidgetState extends State<_TextFormFieldWidget> { .map((MiraiInputFormatter formatter) => formatter.type.format(formatter.rule ?? "")) .toList(), - validator: (value) { - final validation = _validate( - value, - widget.model, - ); - - if (widget.model.id != null) { - // context - // .read() - // .updateValidation(widget.model.id!, validation == null); - } - - return validation; - }, + validator: widget.validator ?? + (value) { + final validation = _validate( + value, + widget.model, + ); + + return validation; + }, ); }