Skip to content

Commit

Permalink
feat: Added validator as a param in mirai-text-field
Browse files Browse the repository at this point in the history
  • Loading branch information
i-asimkhan committed Oct 26, 2023
1 parent 75b6c9b commit 439b16f
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class MiraiTextFormFieldParser extends MiraiParser<MiraiTextFormField> {
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<String, dynamic> json) =>
Expand All @@ -35,6 +37,7 @@ class MiraiTextFormFieldParser extends MiraiParser<MiraiTextFormField> {
model: model,
controler: controler,
onChange: onChange,
validator: validator,
);
}
}
Expand All @@ -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();
Expand Down Expand Up @@ -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<MiraiFormCubit>()
// .updateValidation(widget.model.id!, validation == null);
}

return validation;
},
validator: widget.validator ??
(value) {
final validation = _validate(
value,
widget.model,
);

return validation;
},
);
}

Expand Down

0 comments on commit 439b16f

Please sign in to comment.