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

[Bug] Opening drowdown after focus on other field. #28

Closed
Danaru87 opened this issue Mar 9, 2020 · 6 comments
Closed

[Bug] Opening drowdown after focus on other field. #28

Danaru87 opened this issue Mar 9, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@Danaru87
Copy link
Contributor

Danaru87 commented Mar 9, 2020

When you have a Dropdown,

if you focus another field, when coming back to list will open => close very fast the list and close => open the keyboard giving focus to the field.

Seems to be a bug of https://github.com/adee42/flutter_keyboard_visibility, onChange never fired.

in dropdown_field_bloc_builder.dart, lines 268 - 275, changing:

if (_keyboardVisibility.isKeyboardVisible) {
        //_effectiveFocusNode.requestFocus();
        await Future<void>.delayed(Duration(milliseconds: 1));
        _effectiveFocusNode.unfocus();
        await Future<void>.delayed(Duration(
            milliseconds:
                widget.millisecondsForShowDropdownItemsWhenKeyboardIsOpen));
      }

by

 if (MediaQuery.of(context).viewInsets.bottom != 0) {
        FocusScope.of(context).requestFocus(new FocusNode());
        await Future.delayed(Duration(milliseconds: 1));
      }

solved this bug.
Solution based on comments from the link into your TODO comment. (line 267)

flutter/flutter#18672 (comment)

@jawadsahil
Copy link

I just came across this issue, and I was thinking to post the issue :) But it is already here ... Thanks

@GiancarloCode GiancarloCode added the bug Something isn't working label Mar 10, 2020
@GiancarloCode
Copy link
Owner

@Danaru87 Thanks for reporting this

MediaQuery.of(context).viewInsets.bottom != 0 Always return false And flutter_keyboard_visibility not work :(.

I need a way to detect if the keyboard is visible but I can't find any that works for now, if you get a way to do it let me know and fix it. I will try to look at this again the day after tomorrow.

@Danaru87
Copy link
Contributor Author

Strange behavior, using MediaQuery.of(context).viewInsets.bottom != 0 worked for me.
Maybe you use a context without SafeArea.

This plugin work to detect keyboard opened or closed: https://github.com/IsaiasSantana/keyboard_utils

But, whith dropdown opened, if you tap outside the dropdown, focus stay on it and dont close option list.

I'm working on a solution.

Danaru87 added a commit to UPrefer/form_bloc that referenced this issue Mar 10, 2020
- Fix keyboard detection
- Add boolean to store if focus was requested after closing keyboard
@Danaru87
Copy link
Contributor Author

PR ready #32 .

The code is not super clean, if you have any suggestions I can make the necessary changes.

For those who can't wait for a new release, you can refer my repository into your pubspec.yaml:

  flutter_form_bloc:
    git:
      url: https://github.com/UPrefer/form_bloc.git
      path: packages/flutter_form_bloc

@GiancarloCode
Copy link
Owner

Fixed in form_bloc 0.10.4.
Thank you @Danaru87

@GiancarloCode
Copy link
Owner

GiancarloCode commented Mar 11, 2020

P.D. @Danaru87 @jawadsahil Checkout pinned issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants