didChangeDependencies method

  1. @override
void didChangeDependencies()
override

Called when a dependency of this State object changes.

Implementation

@override
void didChangeDependencies() {
  super.didChangeDependencies();
  final parentScope = Focus.of(context);
  if (_focusNode.parent != parentScope) {
    final p = _focusNode.parent;
    if (parentScope != null) {
      parentScope.addChild(_focusNode);
    } else if (p != null) {
      // Clean up parenting relationship via removeChild instead of directly
      // mutating the parent's children list, which would bypass state propagation
      // and leave the parent node in an inconsistent state if this child had focus.
      p.removeChild(_focusNode);
    } else if (_focusNode.hasFocus) {
      _focusNode.unfocus();
    }
  }
}