StringSchema class final
Schema for validating string values.
- Inheritance
- Mixed-in types
- Available extensions
- Annotations
-
- @immutable
Constructors
-
StringSchema({bool isNullable = false, bool isOptional = false, String? description, List<
Constraint< constraints = const [], List<String> >Refinement< refinements = const []})String> > -
const
Properties
- acceptsNull → bool
-
Whether
parse(null)andencode(null)should accept null without raising a non-nullable failure. Defaults to isNullable; subclasses with branch-level null policies (e.g. AnyOfSchema) override this hook.no setterinherited - baseFieldsHashCode → int
-
Computes hash code for base schema fields.
no setterinherited
-
constraints
→ List<
Constraint< String> > -
Returns an unmodifiable view of the constraints for this schema.
no setterinherited
- description → String?
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
- isNullable → bool
-
finalinherited
- isOptional → bool
-
finalinherited
-
refinements
→ List<
Refinement< String> > -
Returns an unmodifiable view of the refinements for this schema.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schemaType → SchemaType
-
The schema type category for this schema.
no setteroverride
- schemaTypeName → String
-
Human-readable type name for error messages and debugging.
no setterinherited
Methods
-
applyConstraintsAndRefinements(
String value, SchemaContext context) → SchemaResult< String> -
Applies constraints and refinements to a runtime value.
inherited
-
baseFieldsEqual(
AckSchema other) → bool -
Compares base schema fields for equality.
inherited
-
constrain(
Constraint< String> constraint, {String? message}) → StringSchema -
Adds a raw
constraintto the schema.inherited -
contains(
String pattern, {String? example, String? message}) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must contain the givenpatternsomewhere. -
copyWith(
{bool? isNullable, bool? isOptional, String? description, List< Constraint< ? constraints, List<String> >Refinement< ? refinements}) → StringSchemaString> > -
Returns a copy of this schema with the given fields replaced.
override
-
date(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid ISO 8601 date (YYYY-MM-DD). -
datetime(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid ISO 8601 date-time. -
describe(
String description) → StringSchema -
Sets the description for the schema.
inherited
-
email(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid email address. -
encode(
String? value, {String? debugName}) → String? -
Encodes a runtime value to a boundary value, throwing on failure.
inherited
-
encodeAsBoundary(
String value, SchemaContext context) → SchemaResult< String> -
Helper for schemas whose boundary == runtime: validates the runtime
value and, if it passes, returns it as the boundary value unchanged.
Only safe to call when
BoundaryandRuntimeare the same type.inherited -
encodeWithContext(
String value, SchemaContext context) → SchemaResult< String> -
Encodes a runtime value into a boundary value. The base class strips
nullbefore calling this; subclasses receive a non-nullvalue.inherited -
endsWith(
String value) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must end withvalue. -
failNonNullable(
SchemaContext context) → SchemaResult< String> -
Runtime-side non-nullable failure.
inherited
-
failNonNullableEncode(
SchemaContext context) → SchemaResult< String> -
Encode-side non-nullable failure.
inherited
-
handleNullInput(
Object? inputValue, SchemaContext context) → SchemaResult< String> ? -
Centralized null gate for the parse/validate paths. Returns null when
inputValueis non-null; otherwise returns Ok(null) if acceptsNull is true or a non-nullable failure.inherited -
ip(
{int? version}) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid IP address. Ifversionis provided, it must be 4 or 6. -
ipv4(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid IPv4 address. -
ipv6(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid IPv6 address. -
length(
int n) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string's length must be exactlyn. -
matches(
String pattern, {String? example, String? message}) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must match the given regex pattern. -
maxLength(
int n) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string's length must be no more thann. -
minLength(
int n) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string's length must be at leastn. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notEmpty(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must not be empty. -
nullable(
{bool value = true}) → StringSchema -
Marks the schema as nullable.
inherited
-
optional(
{bool value = true}) → StringSchema -
Marks the schema as optional so the field can be omitted from an object.
inherited
-
parse(
Object? value, {String? debugName}) → String? -
Parses and validates a value, throwing an AckException if it fails.
inherited
-
parseAs<
TOut extends Object> (Object? value, TOut map(String? validated), {String? debugName}) → TOut -
Parses and validates a value, then maps the validated value to
TOut.inherited -
parseWithContext(
Object? value, SchemaContext context) → SchemaResult< String> -
Decodes a boundary value into a runtime value.
inherited
-
refine(
bool validate(String value), {String message = 'The value did not pass the custom validation.'}) → StringSchema -
Adds a custom validation check that runs after all other validations.
inherited
-
safeEncode(
String? value, {String? debugName}) → SchemaResult< String> -
Encodes a runtime value to a boundary value, returning a SchemaResult.
inherited
-
safeParse(
Object? value, {String? debugName}) → SchemaResult< String> -
Parses and validates a value, returning a SchemaResult.
inherited
-
safeParseAs<
TOut extends Object> (Object? value, TOut map(String? validated), {String? debugName}) → SchemaResult< TOut> -
Parses and validates a value, then maps the validated value to
TOut.inherited -
startsWith(
String value) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must start withvalue. -
time(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid time (HH:MM:SS). -
toJsonSchema(
) → Map< String, Object?> -
Converts this schema to a JSON Schema Draft-7 representation.
inherited
-
toLowerCase(
) → CodecSchema< String, String> -
Available on StringSchema, provided by the StringSchemaExtensions extension
Converts the string to lowercase after validation. Returns a one-way codec that applies String.toLowerCase() to the input. -
toMap(
) → Map< String, Object?> -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
toUpperCase(
) → CodecSchema< String, String> -
Available on StringSchema, provided by the StringSchemaExtensions extension
Converts the string to uppercase after validation. Returns a one-way codec that applies String.toUpperCase() to the input. -
trim(
) → CodecSchema< String, String> -
Available on StringSchema, provided by the StringSchemaExtensions extension
Trims leading and trailing whitespace from the string before validation. Returns a one-way codec that applies String.trim() to the input. -
uri(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid URI. -
url(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid URI. -
uuid(
) → StringSchema -
Available on StringSchema, provided by the StringSchemaExtensions extension
Adds a constraint that the string must be a valid UUID. -
validateRuntimeWithContext(
Object? value, SchemaContext context) → SchemaResult< String> -
Validates that
valueis a valid runtime value for this schema.override -
withConstraint(
Constraint< String> constraint) → StringSchema -
Adds a validation constraint to the schema.
inherited
-
withConstraints(
List< Constraint< newConstraints) → StringSchemaString> > -
Adds a list of validation constraints to the schema.
inherited
-
withDefault(
String defaultValue) → DefaultSchema< String, String> -
Wraps this schema in a DefaultSchema that supplies
defaultValuewhen the parse input is null. Object encode also injects encoded defaults for missing default-wrapped fields.inherited -
withRuntimeConfig(
{bool? isNullable, bool? isOptional, String? description, List< Constraint< ? constraints, List<String> >Refinement< ? refinements}) → StringSchemaString> > -
Returns a copy of this schema with runtime-side configuration replaced.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override