Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with a flutter_typeahead inside a KeyboardActions #231

Open
BenjiFarquhar opened this issue Jun 16, 2023 · 0 comments
Open

Problem with a flutter_typeahead inside a KeyboardActions #231

BenjiFarquhar opened this issue Jun 16, 2023 · 0 comments

Comments

@BenjiFarquhar
Copy link
Contributor

BenjiFarquhar commented Jun 16, 2023

I'm having an issue when I place a flutter_typeahead inside a KeyboardActions. If I pass the focus node to the TypeAheadFormField, then when I select a suggestion from the dropdown list, this code here clears the focus from the TypeAheadFormField too soon, which causes the onSuggestionSelected callback not to be called, as it can only be called if it has focus:

  /// Insert the keyboard bar as an Overlay.
  ///
  /// This will be inserted above everything else in the MaterialApp, including dialog modals.
  ///
  /// Position the overlay based on the current [MediaQuery] to land above the keyboard.
  void _insertOverlay() {
    OverlayState os = Overlay.of(context);
    _inserted = true;
    _overlayEntry = OverlayEntry(builder: (context) {
      // Update and build footer, if any
      _currentFooter = (_currentAction!.footerBuilder != null)
          ? _currentAction!.footerBuilder!(context)
          : null;

      final queryData = MediaQuery.of(context);
      return Stack(
        children: [
          if (widget.tapOutsideBehavior != TapOutsideBehavior.none ||
              // ignore: deprecated_member_use_from_same_package
              widget.tapOutsideToDismiss)
            Positioned.fill(
              child: Listener(
                onPointerDown: (event) {
                  if (!widget.keepFocusOnTappingNode ||
                      _currentAction?.focusNode.rect.contains(event.position) !=
                          true) {
                    _clearFocus(); ////////////////////////////////////// <- this line prevents onSuggestionSelected callback from running
                  }
                },

If I pass the focus node into my widget that wraps the TypeAheadFormField, the issue seems to resolve; I think because it checks _currentAction?.focusNode.rect.contains(event.position), and the focus node rect is much larger, and includes the drop-down box, so _clearFocus() doesn't run. However, this removes the keyboard_actions keyboard toolbar. Does anyone know of a workaround I can do? I am still investigating options, so I will update this if I figure something out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant