JsonFieldState<SC extends Schema> class abstract

The immutable state of one field of the form: the value, the resolved schema fragment it was built from, the validation result, and the anyOf/oneOf variant machinery. Concrete subclasses (StringFieldState, ObjectFieldState, ...) add their type-specific parts.

States are built by JsonHandlerRegistry.buildState, rendered by the matching JsonFieldHandler, and replaced wholesale on every edit — a handler's onChanged always delivers a NEW state.

Implementers
Available extensions

Constructors

JsonFieldState({required PresenceValue value, required List<JsonFieldState<Schema>>? variants, required Schema? rootSchema, FieldAnnotations? fieldAnnotations, Set<int> matchedVariantIndices = const {}, String? title, SC? schema, List<ValidationError>? errors})
Creates the common part of a field state.
const

Properties

curVariant → JsonFieldState<Schema>?
The state of the single matched variant, or null when nothing matched or the match is unresolvable.
no setter
errors → List<ValidationError>?
Validation result of this state.
final
errorsAsString → String?
The validation messages joined for display, or null when there are none.
no setter
fieldAnnotations → FieldAnnotations?
Presentation annotations from the resolved schema (description, examples, required, default, readOnly).
final
hasErrors → bool
Validated and failed.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasValue → bool
Whether the document carries a value for this field (an explicit null counts as a value).
no setter
isValid → bool
Validated and clean. False both for a failed validation and for a state that was never validated.
no setter
isValidated → bool
Whether validation has run for this state (see errors).
no setter
matchedVariantIndices → Set<int>
The anyOf/oneOf alternatives matched against the value.
final
rootSchema → Schema?
The whole schema document, needed to resolve document-local $refs reachable from schema.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
schema → SC?
Kept here and used only for determining the best schema via the closestVariantIndices function. If not for it, the schema would not be needed here in most cases (Map, List). Try to avoid using this schema, preferring the State properties instead.
final
title → String?
The field label (the schema's title or a derived fallback).
final
value → PresenceValue
The field's value slice of the document; absent when the document does not carry this field.
final
valueOrNull → dynamic
The value, or null when it is absent — indistinguishable from an explicit null; use value where the distinction matters.
no setter
variants → List<JsonFieldState<Schema>>?
One pre-built state per anyOf/oneOf alternative (or per synthesized type branch); null when the schema offers no alternatives. See the staleness contract on copyWith.
final

Methods

applyErrors(List<ValidationError> errors) → JsonFieldState<SC>
Stores a validation result, marking the state as validated: an empty errors list is kept as an empty list (validated clean), never collapsed to null (null means validation has not run, see errors).
applyVariantUpdate(int index, JsonFieldState<Schema> variantState, PresenceValue? emptyValue) → JsonFieldState<SC>
Returns this unchanged if index is out of the bounds of variants (the assert fires only in debug). Public callers must check the bounds themselves beforehand and report the violation via a platform-appropriate mechanism (see ObjectField._onVariantChanged) — this method does not guarantee error visibility in production.
clear() → JsonFieldState<SC>
A copy with the value removed from the document (absent, not null).
copyWith({PresenceValue? value, Set<int>? matchedVariantIndices, List<JsonFieldState<Schema>>? variants}) → JsonFieldState<SC>
Staleness contract: a point write (e.g. copyWith(value:)) does NOT refresh derived parts. variants entries keep the states built for the value at buildState time — applyVariantUpdate replaces only the edited entry, applyVariantSwitched refreshes only the switched-to entry with the written value — and matchedVariantIndices is not recomputed on value writes. Consumers must treat both as build-time snapshots, not live views of the current value.
isSubmittable(SchemaValidationMode mode) → bool

Available on JsonFieldState<Schema>, provided by the SubmittableJsonFieldState extension

Whether submission gates (the dialogs' OK buttons) accept this state under mode: validated and free of blocking errors. Under SchemaValidationMode.strict every error blocks (equivalent to JsonFieldState.isValid); under SchemaValidationMode.lenient a validator-rejected schema does not. Under SchemaValidationMode.none validation is skipped, so a validated state is clean by construction — the lenient rule returns the same result.
markUnvalidated() → JsonFieldState<SC>
A copy marked as not validated (errors = null, see the contract there); this when the state has not been validated already.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rebuild({required PresenceValue value, required Set<int> matchedVariantIndices, required List<JsonFieldState<Schema>>? variants, required List<ValidationError>? errors}) → JsonFieldState<SC>
The low-level copy constructor — the ONE method a subclass implements (a plain constructor call passing the parameters through and carrying its own extra fields over). Every parameter is required and written verbatim; there is no null-means-keep convention here — that lives in copyWith, and the errors semantics live in applyErrors / markUnvalidated, all implemented on top of this.
resolveVariantUpdate(JsonFieldState<Schema> variantState, List<JsonFieldState<Schema>> actualVariants, PresenceValue? emptyValue) → JsonFieldState<SC>
Applies an edit made inside a variant branch: adopts the branch state's value (falling back to emptyValue, then to the current value, when the branch carries none) and stores the updated actualVariants. Containers override this to merge instead of replace (see ObjectFieldState).
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited