Skip to content

Validating a string ends with a substring

import 'package:luthor/luthor.dart';
void main() {
final validator = l.string().endsWith('World!');
print(validator.validateValue('Hello World!'));
}
import 'package:luthor/luthor.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'ends_with.freezed.dart';
part 'ends_with.g.dart';
@luthor
@freezed
abstract class EndsWithSchema with _$EndsWithSchema {
const factory EndsWithSchema({
@EndsWith('World!') required String value,
}) = _EndsWithSchema;
factory EndsWithSchema.fromJson(Map<String, dynamic> json) =>
_$EndsWithSchemaFromJson(json);
}
void main() {
final result = $EndsWithSchemaValidate({'value': 'Hello World!'});
switch (result) {
case SchemaValidationSuccess(data: final data):
print('✅ Valid: ${data.value}');
case SchemaValidationError(errors: final errors):
print('❌ Errors: $errors');
}
}