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.
Constructors
-
JsonFieldState({required PresenceValue value, required List<
JsonFieldState< ? variants, required Schema? rootSchema, FieldAnnotations? fieldAnnotations, Set<Schema> >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
titleor 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
errorslist is kept as an empty list (validated clean), never collapsed to null (null means validation has not run, seeerrors). -
applyVariantUpdate(
int index, JsonFieldState< Schema> variantState, PresenceValue? emptyValue) → JsonFieldState<SC> -
Returns
thisunchanged ifindexis 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< ? variants}) → JsonFieldState<Schema> >SC> -
Staleness contract: a point write (e.g.
copyWith(value:)) does NOT refresh derived parts.variantsentries 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 — andmatchedVariantIndicesis 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<
Whether submission gates (the dialogs' OK buttons) accept this state underSchema> , provided by the SubmittableJsonFieldState extensionmode: 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);
thiswhen 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< ? variants, required List<Schema> >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
errorssemantics live in applyErrors / markUnvalidated, all implemented on top of this. -
resolveVariantUpdate(
JsonFieldState< Schema> variantState, List<JsonFieldState< actualVariants, PresenceValue? emptyValue) → JsonFieldState<Schema> >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 updatedactualVariants. 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