2021-01-06 17:35:57 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
2022-05-02 11:56:46 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2022-05-02 11:56:46 +00:00
|
|
|
abstract class LengthStringValidation extends ValidationModel<String> {
|
2022-06-05 19:36:32 +00:00
|
|
|
LengthStringValidation(super.predicate, super.errorMessage);
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
String? check(final String val) {
|
|
|
|
final int length = val.length;
|
2022-06-05 22:40:34 +00:00
|
|
|
final String errorMessage =
|
|
|
|
errorMassage.replaceAll('[]', length.toString());
|
2022-05-25 12:21:56 +00:00
|
|
|
return test(val) ? errorMessage : null;
|
2021-01-06 17:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-02 11:56:46 +00:00
|
|
|
|
|
|
|
class LengthStringNotEqualValidation extends LengthStringValidation {
|
2022-05-04 19:32:24 +00:00
|
|
|
/// String must be equal to [length]
|
2022-06-05 19:36:32 +00:00
|
|
|
LengthStringNotEqualValidation(final int length)
|
2022-06-05 22:40:34 +00:00
|
|
|
: super(
|
|
|
|
(final n) => n.length != length,
|
|
|
|
'validations.length_not_equal'.tr(args: [length.toString()]),
|
|
|
|
);
|
2022-05-02 11:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class LengthStringLongerValidation extends LengthStringValidation {
|
2022-05-04 19:32:24 +00:00
|
|
|
/// String must be shorter than or equal to [length]
|
2022-06-05 19:36:32 +00:00
|
|
|
LengthStringLongerValidation(final int length)
|
2022-06-05 22:40:34 +00:00
|
|
|
: super(
|
|
|
|
(final n) => n.length > length,
|
|
|
|
'validations.length_longer'.tr(args: [length.toString()]),
|
|
|
|
);
|
2022-05-02 11:56:46 +00:00
|
|
|
}
|