handleFocusChange method

void handleFocusChange()
inherited

Implementation

void handleFocusChange() {
  if (_isFocus) {
    widgetElement.oldValue = widgetElement.value;
    scheduleMicrotask(() {
      widgetElement.dispatchEvent(dom.FocusEvent(dom.EVENT_FOCUS, relatedTarget: widgetElement));
    });

    HardwareKeyboard.instance.addHandler(_handleKey);
    // Try to keep the focused input visible within the nearest overflow scroll container.
    WidgetsBinding.instance.addPostFrameCallback((_) {
      // A second pass after the keyboard animates in.
      Future.delayed(const Duration(milliseconds: 350), () {
        // if (mounted) _scrollIntoNearestOverflow();
        if (mounted) {
          // Use alignment=1.0 to position input at bottom of viewport for better keyboard visibility
          WebFEnsureVisible.acrossScrollables(context, alignment: 1.0);
        }
      });
    });
  } else {
    if (widgetElement.oldValue != widgetElement.value) {
      scheduleMicrotask(() {
        widgetElement.dispatchEvent(dom.Event('change'));
      });
    }
    scheduleMicrotask(() {
      widgetElement.dispatchEvent(dom.FocusEvent(dom.EVENT_BLUR, relatedTarget: widgetElement));
    });

    HardwareKeyboard.instance.removeHandler(_handleKey);
  }
}