A11yLensOverlay class
Wrap the root of an app in A11yLensOverlay to audit it live:
void main() {
runApp(A11yLensOverlay(child: const MyApp()));
}
After every frame, it walks the widget tree below child, runs rules and semanticsRules against the snapshot, and draws a colored outline over each violating widget — red for A11ySeverity.error, amber for A11ySeverity.warning, blue for A11ySeverity.info. Tapping an outline opens a popover with the rule, message, and suggested fix.
semanticsRules (on by default) reads the real SemanticsNode tree
rather than the Element tree, so it needs an active SemanticsHandle
to make the engine compute it — this widget acquires one automatically
whenever semanticsRules is non-empty, for as long as it's mounted and
enabled. That has a real (debug/profile-only) performance cost; pass
semanticsRules: [] to opt out if it matters for a given session. Its
own outline/popover widgets are built with excludeFromSemantics: true
so they never show up in that tree themselves.
A no-op in release builds: build returns child unchanged, so the
walkers, rules, and overlay widgets are all compiled away since
kReleaseMode is a compile-time constant. Set enabled to false to
also disable it in debug/profile builds (e.g. behind a feature flag).
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- A11yLensOverlay
Constructors
-
A11yLensOverlay({Key? key, required Widget child, List<
A11yRule> rules = const [ContrastRule(), TapTargetSizeRule()], List<A11ySemanticsRule> semanticsRules = const [SemanticLabelRule(), FocusOrderRule()], bool enabled = true}) -
const
Properties
- child → Widget
-
final
- enabled → bool
-
Set to false to disable auditing without removing the widget (e.g.
from a debug settings toggle). Has no effect in release builds, which
are always disabled.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
rules
→ List<
A11yRule> -
Element-tree-based checks run against every walked frame. Defaults to
the built-in contrast and tap-target-size rules; pass a custom list to
add team-specific rules or drop the defaults.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
semanticsRules
→ List<
A11ySemanticsRule> -
Semantics-tree-based checks run against every walked frame. Defaults
to the built-in semantic-label and focus-order rules. Pass an empty
list to disable semantics auditing (and the SemanticsHandle it
requires) entirely.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< A11yLensOverlay> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited