Make a value Required / Non-nullable
To make a value required, you can use the required modifier. This will ensure that the value is not null.
import 'package:luthor/luthor.dart';
void main() { final validator = l.string().required(); print(validator.validateValue('Hello'));}Note: When using code generation, using the
requiredkeyword in the Freezed class will make the value required automatically.
import 'package:luthor/luthor.dart';import 'package:freezed_annotation/freezed_annotation.dart';
part 'required_schema.freezed.dart';part 'required_schema.g.dart';
@luthor@freezedabstract class RequiredSchema with _$RequiredSchema { const factory RequiredSchema({ // Adds the required modifier to the value required String value, }) = _RequiredSchema;
factory RequiredSchema.fromJson(Map<String, dynamic> json) => _$RequiredSchemaFromJson(json);}
void main() { final result = $RequiredSchemaValidate({'value': 'Hello'});
switch (result) { case SchemaValidationSuccess(data: final data): print('✅ Valid: ${data.value}'); case SchemaValidationError(errors: final errors): print('❌ Errors: $errors'); }}