firestoreodm-flutter
firestoreodm-flutter copied to clipboard
Validator over multiple values
Feature Request
Consider a odm like this:
@firestoreSerializable
class TimeFrame {
final Timestamp start;
final Timestamp end;
TimeFrame(this.lowerLimit, this.upperLimit) {
_$assertTimeFrame(this);
}
}
I would like to validate that start
is before end
.
Idea
abstract class ValidatorWithOther<T> {
const ValidatorWithOther(this.otherPropertyName);
final String otherPropertyName;
void validate(Object? value, T other, String propertyName);
}
that could be extended
class IsAfterValidator extends ValidatorWithOther<Timestamp> {
const IsAfterValidator(super.otherPropertyName);
@override
void validate(Object? value, Timestamp other, String propertyName) {
// TODO: implement validate
}
}
And then applied to a property
@firestoreSerializable
class TimeFrame {
final Timestamp start;
@IsAfterValidator('start')
final Timestamp end;
TimeFrame(this.lowerLimit, this.upperLimit) {
_$assertTimeFrame(this);
}
}
code generation should throw an exception if the other parameter with the correct Type does not exist. (maybe even a custom_lint)