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

How unfocus the HtmlEditor to close keyboard? #26

Open
GuilhermeDemoliner opened this issue Aug 9, 2021 · 11 comments
Open

How unfocus the HtmlEditor to close keyboard? #26

GuilhermeDemoliner opened this issue Aug 9, 2021 · 11 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@GuilhermeDemoliner
Copy link

I need to close keyboard by onTap in Parent, but not found where to configure FocusNode of editor.
I have:
final GlobalKey<HtmlEditorState> _keyEditor = GlobalKey<HtmlEditorState>();
with:
HtmlEditor(key: _keyEditor,)

@robert-virkus robert-virkus added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 9, 2021
@robert-virkus
Copy link
Member

Have you tried FocusScope?

FocusScope.of(context).unfocus();

Haven't tried it myself yet, but it's worth a shot.

@GuilhermeDemoliner
Copy link
Author

Have you tried FocusScope?

FocusScope.of(context).unfocus();

Haven't tried it myself yet, but it's worth a shot.

Yes already tried that and this to:

   FocusScopeNode currentFocus = FocusScope.of(context);

    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      currentFocus.focusedChild.unfocus();
    }

@robert-virkus
Copy link
Member

Still haven't found a solution to this problem. Having other input fields and tapping on them works as expected, but I didn't manage to just unfocus the HTML editor. I assume this may be related to using the hybrid composition of the InAppWebView, but I am not sure.

What platform do you mainly work on (Android or iOS)?

@GuilhermeDemoliner GuilhermeDemoliner changed the title How onfocus the HtmlEditor to close keyboard? How unfocus the HtmlEditor to close keyboard? Aug 10, 2021
@robert-virkus
Copy link
Member

Good news: For Android I have found a solution. Bad news: for this I had to change the clearFocus() Method of InputAwareWebView.java in the InAppWebView project.

There is now a HtmlEditorApi.unfocus() method, that you can use to close the keyboard, e.g. with the HtmlEditorApi? _editorApi field:

TextButton( 
  child: Text('Close'),
  onPressed: () => _editorApi?.unfocus(),
),

You can test this by using this dependency in your pubspec.yaml:

  enough_html_editor: 
    git:
      url: https://github.com/Enough-Software/enough_html_editor.git

@GuilhermeDemoliner
Copy link
Author

I believe the package is overwriting some flutter classes, so this error occurs:

./../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_list_tile.dart:14:9: Error: Type 'MouseCursor' not found.
  final MouseCursor? mouseCursor;
        ^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/decorated_platform_textfield.dart:309:9: Error: Type 'MouseCursor' not found.
  final MouseCursor? mouseCursor;
        ^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_icon_button.dart:17:9: Error: Type 'MouseCursor' not found.
  final MouseCursor mouseCursor;
        ^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_toggle_buttons.dart:10:9: Error: Type 'MouseCursor' not found.
  final MouseCursor? mouseCursor;
        ^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dartlang.org/flutter_colorpicker-0.5.0/lib/src/hsv_picker.dart:730:43: Error: The parameter 'event' of the method 'AlwaysWinPanGestureRecognizer.addAllowedPointer' has type 'PointerDownEvent', which does not match the corresponding type, 'PointerEvent', in the overridden method, 'DragGestureRecognizer.addAllowedPointer'.
 - 'PointerDownEvent' is from 'package:flutter/src/gestures/events.dart' ('../../../fvm/versions/2.0.6/packages/flutter/lib/src/gestures/events.dart').
 - 'PointerEvent' is from 'package:flutter/src/gestures/events.dart' ('../../../fvm/versions/2.0.6/packages/flutter/lib/src/gestures/events.dart').
Change to a supertype of 'PointerEvent', or, for a covariant parameter, a subtype.
  void addAllowedPointer(PointerDownEvent event) {

                                          ^
../../../fvm/versions/2.0.6/packages/flutter/lib/src/gestures/monodrag.dart:256:8: Context: This is the overridden method ('addAllowedPointer').
  void addAllowedPointer(PointerEvent event) {
       ^

../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_icon_button.dart:43:26: Error: Getter not found: 'SystemMouseCursors'.
      this.mouseCursor = SystemMouseCursors.click,
                         ^^^^^^^^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/cupertino/cupertino_snack_app.dart:99:7: Error: No named parameter with the name 'scrollBehavior'.
      scrollBehavior: scrollBehavior,

      ^^^^^^^^^^^^^^
../../../fvm/versions/2.0.6/packages/flutter/lib/src/cupertino/app.dart:138:9: Context: Found this candidate, but the arguments don't match.
  const CupertinoApp({
        ^^^^^^^^^^^^

../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_list_tile.dart:14:9: Error: 'MouseCursor' isn't a type.
  final MouseCursor? mouseCursor;
        ^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/decorated_platform_textfield.dart:309:9: Error: 'MouseCursor' isn't a type.
  final MouseCursor? mouseCursor;

        ^^^^^^^^^^^
../../../.pub-cache/git/enough_platform_widgets-e06bb5f567d5f4e53fb2c078ca56128f62cb4191/lib/src/platform/platform_dropdown_button.dart:82:9: Error: No named parameter with the name 'menuMaxHeight'.
        menuMaxHeight: menuMaxHeight,
        ^^^^^^^^^^^^^

../../../fvm/versions/2.0.6/packages/flutter/lib/src/material/dropdown.dart:830:3: Context: Found this candidate, but the arguments don't match.
  DropdownButton({
  ^^^^^^^^^^^^^^


@robert-virkus
Copy link
Member

You are right, the package enough_platform_widgets also needs to be used in pubspec.yaml:

environment:
  sdk: '>=2.12.0 <3.0.0'
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  enough_platform_widgets:
    git:
      url: https://github.com/Enough-Software/enough_platform_widgets.git
  enough_html_editor: 
    git:
      url: https://github.com/Enough-Software/enough_html_editor.git

Run flutter pub upgrade to ensure everything is up-to-date.

@GuilhermeDemoliner
Copy link
Author

GuilhermeDemoliner commented Aug 12, 2021

I

You are right, the package enough_platform_widgets also needs to be used in pubspec.yaml:

environment:
  sdk: '>=2.12.0 <3.0.0'
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  enough_platform_widgets:
    git:
      url: https://github.com/Enough-Software/enough_platform_widgets.git
  enough_html_editor: 
    git:
      url: https://github.com/Enough-Software/enough_html_editor.git

Run flutter pub upgrade to ensure everything is up-to-date.

My project cannot be upgraded to SDK 2.12.0 due to incompatibility of some dependencies. So I couldn't test your suggestion.

@robert-virkus
Copy link
Member

ok, please verify once you have upgraded your Flutter environment.

@robert-virkus
Copy link
Member

I just realized that your compile error is mostly due to a flutter_colorpicker bug. I have now downgraded the flutter_colorpicker version in the pubspec.yaml on HEAD, you might want to try again.

@MrShailandra
Copy link

I think this should be work

SystemChannels.textInput.invokeMethod('TextInput.hide');

@robert-virkus
Copy link
Member

Thanks a lot, this seems to work fine - I added your code now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants