attach method

  1. @mustCallSuper
FocusAttachment attach(
  1. BuildContext? context,
  2. {FocusOnKeyEventCallback? onKeyEvent,
  3. @Deprecated('Use onKeyEvent instead. ' 'This feature was deprecated after v3.18.0-2.0.pre.') FocusOnKeyCallback? onKey}
)

Called by the host StatefulWidget to attach a FocusNode to the widget tree.

In order to attach a FocusNode to the widget tree, call attach, typically from the StatefulWidget's State.initState method.

If the focus node in the host widget is swapped out, the new node will need to be attached. FocusAttachment.detach should be called on the old node, and then attach called on the new node. This typically happens in the State.didUpdateWidget method.

To receive key events that focuses on this node, pass a listener to onKeyEvent.

Implementation

@mustCallSuper
FocusAttachment attach(
  BuildContext? context, {
  FocusOnKeyEventCallback? onKeyEvent,
  @Deprecated(
    'Use onKeyEvent instead. '
    'This feature was deprecated after v3.18.0-2.0.pre.',
  )
  FocusOnKeyCallback? onKey,
}) {
  _context = context;
  this.onKey = onKey ?? this.onKey;
  this.onKeyEvent = onKeyEvent ?? this.onKeyEvent;
  _attachment = FocusAttachment._(this);
  return _attachment!;
}