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> {
|
|
|
|
LengthStringValidation(bool Function(String) predicate, String errorMessage)
|
|
|
|
: super(predicate, errorMessage);
|
2021-01-06 17:35:57 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-02 11:56:46 +00:00
|
|
|
String? check(String value) {
|
|
|
|
var length = value.length;
|
|
|
|
var errorMessage = this.errorMassage.replaceAll("[]", length.toString());
|
|
|
|
return test(value) ? 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-05-02 11:56:46 +00:00
|
|
|
LengthStringNotEqualValidation(int length)
|
|
|
|
: super((n) => n.length != length,
|
|
|
|
'validations.length_not_equal'.tr(args: [length.toString()]));
|
|
|
|
}
|
|
|
|
|
|
|
|
class LengthStringLongerValidation extends LengthStringValidation {
|
2022-05-04 19:32:24 +00:00
|
|
|
/// String must be shorter than or equal to [length]
|
2022-05-02 11:56:46 +00:00
|
|
|
LengthStringLongerValidation(int length)
|
|
|
|
: super((n) => n.length > length,
|
|
|
|
'validations.length_longer'.tr(args: [length.toString()]));
|
|
|
|
}
|