validate library

Strict validation of layout documents: what the lenient decoders would silently drop, replace or ignore, as typed diagnostics.

Classes

Codes
Every code validateDocument reports.
Diagnostic
One problem found in a document.
DiagnosticCode
One diagnostic code: its name, severity and what it means.
ValidateOptions
What a document is checked against beyond itself.

Enums

Severity
How bad a Diagnostic is.

Constants

canvasRouteKeys → const Set<String>
The keys a canvas node reads beyond node fields: its URL path, and how it opens from a link (ScreenRoute: under, translucent).
documentKeys → const Set<String>
The keys a layout document reads at its top level.
pageVariablesScope → const String
The variables scope shared by every canvas of a page.
runtimeScopes → const Set<String>
Names the runtime provides to every expression (besides the screen's variables): the app's data, route params, device storage, the screen's size class, the theme, a list's item, the previous action's result, a loop's item, auth, drag and drop, frame timings, node scopes (a track, a dismissible, a pan, a transform gesture, flip card, tilt, view progress, sticky header, form), scripts and speech.
themeKeys → const Set<String>
The keys a theme (the site manifest's theme) reads.
valueForms → const Map<String, String>
The JSON forms each value type reads, as a reader would write them.

Functions

scanExpressions(String text) → ({String? error, List<Expression> expressions})
The expressions in text, and the first syntax problem (an unclosed ${, an empty ${}), as the SDK scans them: quotes and nested braces inside an expression are skipped; \${ is literal.
strictEditCheck([ValidateOptions options = const ValidateOptions()]) → EditCheck
An EditCheck that runs validateDocument on the nodes an op touched (with options: formulas, the project's screens, variables, components and theme). Its diagnostics keep the validator's codes, paths and suggestions; an error rejects the op.
validateDocument(Object? json, {ValidateOptions options = const ValidateOptions()}) → List<Diagnostic>
Checks json, a layout document, against the declarations. Never throws.
validateEdited(LayoutDocument document, {ValidateOptions options = const ValidateOptions()}) → List<Diagnostic>
The document ops build, checked as a whole by validateDocument (what a stream produced, once it ended).
validateProject(Map<String, Object?> documents, {ValidateOptions options = const ValidateOptions(), SiteManifest? manifest}) → List<Diagnostic>
Checks several documents of one project (a site's pages): each against the others' screens and node ids. Keys are file names; diagnostics carry them in Diagnostic.file.
validateSiteFonts(Object? json, {String at = '/fonts'}) → List<Diagnostic>
Checks a site manifest's fonts (at at): a list of families in the shape of a pubspec's fonts: ([{"family": "Inter", "fonts": [{"asset": "fonts/Inter-Bold.ttf", "weight": 700, "style": "italic"}]}]), each file .ttf, .otf or .woff. Whether the files exist is the loader's to say (the render command reports a missing one).
validateTheme(Object? json, {String at = '/theme', Breakpoints? breakpoints}) → List<Diagnostic>
Checks a theme's JSON (the site manifest's theme, at at): its keys, its colors (#AARRGGBB or another color's name), its text styles (as TextStyle, their from and color names against the theme itself) and its media rules (conditions as a node's, patches of colors and text styles).

Typedefs

FormulaChecker = FormulaReport Function(String formula)
Parses formulas for validateDocument. The formula language is the SDK's; pure-Dart validation without one only checks that each ${ closes.
FormulaReport = ({String? error, Set<String> paths})
What a formula checker tells about one formula (the text inside ${= ...}): why it doesn't parse (null when it does) and the variable paths it reads (qty, user.name).