FocusAttachment class

An attachment point for a FocusNode.

Using a FocusAttachment is rarely needed, unless building something akin to the Focus or FocusScope widgets from scratch.

Once created, a FocusNode must be attached to the widget tree by its host StatefulWidget via a FocusAttachment object. FocusAttachments are owned by the StatefulWidget that hosts a FocusNode or FocusScopeNode. There can be multiple FocusAttachments for each FocusNode, but the node will only ever be attached to one of them at a time.

This attachment is created by calling FocusNode.attach, usually from the host widget's State.initState method. If the widget is updated to have a different focus node, then the new node needs to be attached in State.didUpdateWidget, after calling detach on the previous FocusAttachment. Once detached, the attachment is defunct and will no longer make changes to the FocusNode through reparent.

Without these attachment points, it would be possible for a focus node to simultaneously be attached to more than one part of the widget tree during the build stage.

Properties

hashCode int
The hash code for this object.
no setterinherited
isAttached bool
Returns true if the associated node is attached to this attachment.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

detach() → void
Detaches the FocusNode this attachment point is associated with from the focus tree, and disconnects it from this attachment point.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reparent({FocusNode? parent}) → void
Ensures that the FocusNode attached at this attachment point has the proper parent node, changing it if necessary.
toString() String
A string representation of this object.
inherited

Operators

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