Skip to content

Validating a String value

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