attach method Null safety

  1. @mustCallSuper
FocusAttachment attach(
  1. BuildContext? context,
  2. {FocusOnKeyEventCallback? onKeyEvent,
  3. FocusOnKeyCallback? onKey}
)
mustCallSuper">@mustCallSuper

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. The onKey is a legacy API based on RawKeyEvent and will be deprecated in the future.

Implementation

@mustCallSuper
FocusAttachment attach(
  BuildContext? context, {
  FocusOnKeyEventCallback? onKeyEvent,
  FocusOnKeyCallback? onKey,
}) {
  _context = context;
  this.onKey = onKey ?? this.onKey;
  this.onKeyEvent = onKeyEvent ?? this.onKeyEvent;
  _attachment = FocusAttachment._(this);
  return _attachment!;
}