DesignPressable class
Makes any widget a control (press, focus, hover and what a screen reader hears), with no look of its own.
onPressed null and enabled null: disabled (no focus, no hover, a screen reader hears it dimmed, WidgetState.disabled in the states). enabled true with onPressed null: waiting (busy): it keeps its focus, its look and its tap for a screen reader, and a press does nothing, so a control that is working changes neither its node nor its actions.
WidgetState.focused is in the states only while the focus should show (the keyboard moved it, not a tap), so a look draws its ring from it directly.
WidgetState.pressed comes from the pointer itself, as soon as a finger or a button goes down (after kPressTimeout inside a scroll view, so a scroll that starts on it does not light it), and stays at least minimumPressDuration, so a quick tap, shorter than a frame's worth of the press animation, still shows its press. A drag past kTouchSlop lets it go at once: a scroll took the pointer. A long press holds it until the finger lifts.
It is as large as its face, or minimumSize: a DesignTapTargetScope's
floors reach it only through a DesignTapTarget round it. A small icon
(16 by 16) under a touch scope stays 16 by 16 to a finger and to a
screen reader until it is wrapped:
DesignTapTarget(
child: DesignPressable(
semanticLabel: 'Play',
onPressed: play,
builder: (context, states, _) => const SizedBox.square(dimension: 16),
),
)
DesignPressable(onPressed: () {}, semanticLabel: 'Save', builder: (context, states, child) => Opacity(opacity: states.contains(WidgetState.pressed) ? 0.6 : 1, child: const Text('Save')))
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- DesignPressable
Constructors
-
DesignPressable({Key? key, required DesignPressableBuilder builder, Widget? child, VoidCallback? onPressed, VoidCallback? onLongPress, bool? enabled, bool selected = false, bool isError = false, WidgetStatesController? statesController, FocusNode? focusNode, bool autofocus = false, MouseCursor? mouseCursor, Size minimumSize = Size.zero, Map<
ShortcutActivator, Intent> ? shortcuts, Map<Type, Action< ? actions, KeyEventResult onKeyEvent(FocusNode node, KeyEvent event)?, ValueChanged<Intent> >Set< ? onStatesChanged, String? semanticLabel, String? semanticValue, String? semanticHint, bool button = true, bool link = false, bool tab = false, bool? semanticSelected, bool? checked, bool mixed = false, bool? toggled, bool? expanded, bool inMutuallyExclusiveGroup = false, bool excludeSemantics = false, bool enableFeedback = true})WidgetState> > -
A pressable area drawn by
builder.const
Properties
-
actions
→ Map<
Type, Action< ?Intent> > -
More actions, beside ActivateIntent and ButtonActivateIntent.
final
- autofocus → bool
-
Whether it takes focus when it first appears, as Focus.autofocus
does: one part on a route asks for it.
final
- builder → DesignPressableBuilder
-
Draws the face for the current states.
final
-
Its role: a button (the default), a link or a tab.
final
- checked → bool?
-
A screen reader's checked flag, for a checkbox or a radio. Null leaves it out.
final
- child → Widget?
-
Passed to builder untouched.
final
- enabled → bool?
-
Whether it takes focus and reports enabled. Null: whether it has
onPressed or onLongPress. True with neither: waiting.
final
- enableFeedback → bool
-
Whether a tap plays the platform's tap feedback.
final
- excludeSemantics → bool
-
Whether to drop the face's own semantics, so only semanticLabel is
read. Otherwise the face's words merge into the one node.
final
- expanded → bool?
-
A screen reader's expanded flag, for a disclosure. Null leaves it out.
final
- focusNode → FocusNode?
-
Its focus node, when the caller moves focus itself.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- inMutuallyExclusiveGroup → bool
-
One of a set where only one is chosen: a radio.
final
- isError → bool
-
WidgetState.error: what it holds is wrong. The node says so
(SemanticsValidationResult.invalid).
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- link → bool
-
Read as a link rather than a button: it goes somewhere.
final
- minimumSize → Size
-
The least area that takes a tap, the face centred in it (44 by 44 for
a face drawn smaller than a finger).
final
- mixed → bool
-
A checkbox partly ticked.
final
- mouseCursor → MouseCursor?
-
The pointer over it. Null: a click where it presses, else the one
under it. A WidgetStateMouseCursor resolves against the states.
final
- onKeyEvent → KeyEventResult Function(FocusNode node, KeyEvent event)?
-
Keys the shortcuts do not cover, while it or what it holds has focus.
final
- onLongPress → VoidCallback?
-
What a long press does, when anything.
final
- onPressed → VoidCallback?
-
What a press does (a tap, Enter, Space, a screen reader's tap).
final
-
onStatesChanged
→ ValueChanged<
Set< ?WidgetState> > -
Called whenever the states change, after the face is rebuilt.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selected → bool
-
WidgetState.selected: the chosen one of a set, or toggled on.
final
- semanticHint → String?
-
What pressing it does, when the name does not say.
final
- semanticLabel → String?
-
What a screen reader calls it. Null: the words inside it.
final
- semanticSelected → bool?
-
A screen reader's selected flag, when the control is a choice; null
leaves it out. Defaults to nothing even when selected is true: a
pressed toggle says toggled, a checkbox checked.
final
- semanticValue → String?
-
What it holds, read after the name ("3 of 5").
final
-
shortcuts
→ Map<
ShortcutActivator, Intent> ? -
More keys while it has focus, beside Enter and Space (arrows on a
radio group).
final
- statesController → WidgetStatesController?
-
The states, when the caller watches or drives them itself. The
caller's, who disposes it; null: the pressable makes its own and
disposes it.
final
- tab → bool
-
Read as a tab rather than a button: one of a tab bar's, showing its
panel. A screen reader hears it selected or not (semanticSelected,
else selected); a row of them may span its bar where a button keeps
to its content.
final
- toggled → bool?
-
A screen reader's toggled flag, for a switch. Null leaves it out.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< DesignPressable> -
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.
override
-
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
Constants
- minimumPressDuration → const Duration
- The least time WidgetState.pressed stays in the states once a press shows, however quick the tap: long enough for a look's press animation to be seen.