mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-14 12:43:16 +00:00
33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'package:cubit_form/cubit_form.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
abstract class LengthStringValidation extends ValidationModel<String> {
|
|
LengthStringValidation(super.predicate, super.errorMessage);
|
|
|
|
@override
|
|
String? check(final String val) {
|
|
final int length = val.length;
|
|
final String errorMessage =
|
|
errorMassage.replaceAll('[]', length.toString());
|
|
return test(val) ? errorMessage : null;
|
|
}
|
|
}
|
|
|
|
class LengthStringNotEqualValidation extends LengthStringValidation {
|
|
/// String must be equal to [length]
|
|
LengthStringNotEqualValidation(final int length)
|
|
: super(
|
|
(final n) => n.length != length,
|
|
'validations.length_not_equal'.tr(args: [length.toString()]),
|
|
);
|
|
}
|
|
|
|
class LengthStringLongerValidation extends LengthStringValidation {
|
|
/// String must be shorter than or equal to [length]
|
|
LengthStringLongerValidation(final int length)
|
|
: super(
|
|
(final n) => n.length > length,
|
|
'validations.length_longer'.tr(args: [length.toString()]),
|
|
);
|
|
}
|