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

Support notifying soft keyboard visibility updates in Flutter Web apps #10

Open
MisterJimson opened this issue Apr 8, 2020 · 14 comments
Labels
enhancement New feature or request flutter web

Comments

@MisterJimson
Copy link
Owner

Seems like an obvious feature for mobile web apps.

Not sure if there is much we could help with for physical keyboards / desktop web apps.

@MisterJimson MisterJimson added enhancement New feature or request flutter web labels Apr 8, 2020
@MisterJimson MisterJimson mentioned this issue Nov 23, 2020
@otopba
Copy link

otopba commented May 10, 2021

Any updates?

@MisterJimson
Copy link
Owner Author

I spent some time investigating and could not find a solid approach. So nothing yet.

@esase
Copy link

esase commented Jul 15, 2021

@MisterJimson if we cannot listen the keyboard changes in the web it makes this plugin useless there. Maybe you should consider to remove the badge of a compatibility with the web here - https://pub.dev/packages/flutter_keyboard_visibility ??
I spent many time understanding why it does not work in the web despite the plugin's description says another

@MisterJimson
Copy link
Owner Author

@esase its setup like this so your app doesn't break on web if you use this library, it works as normal but just returns false. Can add a note to the readme.

@esase
Copy link

esase commented Jul 15, 2021

@esase its setup like this so your app doesn't break on web if you use this library, it works as normal but just returns false. Can add a note to the readme.

Yes I understand that, my point was that the web is not implemented yet, and yeah a note would be nice

@cmaccarone
Copy link

cmaccarone commented Oct 18, 2022

What if we listened to some native javascript browser events like this

window.addEventListener('native.showkeyboard', keyboardShowHandler); window.addEventListener('native.hidekeyboard', keyboardHideHandler);

Then add some listeners to those?

(edit)

I couldn't get those events to work but this one does

window.visualViewPort.addEventListener('resize', (event) {});

https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport/resize_event

but this doesn't seem to be a very stable route.

@MisterJimson
Copy link
Owner Author

@cmaccarone can you link to documentation for those events?

From a quick search they seem to be specific to Ionic hybrid apps.

@cmaccarone
Copy link

@MisterJimson see my edits

@MisterJimson
Copy link
Owner Author

Thanks. Yes we tried using resize before but we couldn't find a consistent enough implementation.

https://github.com/MisterJimson/flutter_keyboard_visibility/pull/106/files

@renanyoy
Copy link

I managed to find something for the web using


class VisualViewport {
  final _ctrlSizeChanged = StreamController<Size>.broadcast();
  final _ctrlScrollChanged = StreamController<Offset>.broadcast();
  Stream<Size> get onSizeChanged => _ctrlSizeChanged.stream;
  Stream<Offset> get onScrollChanged => _ctrlScrollChanged.stream;
  VisualViewport() {
    window.visualViewport?.onScroll.listen((event) {
      _ctrlScrollChanged.add(Offset(
          (window.visualViewport?.offsetLeft ?? 0).toDouble(),
          (window.visualViewport?.offsetTop ?? 0).toDouble()));
    });
    window.visualViewport?.onResize.listen((event) {
      _ctrlSizeChanged.add(Size((window.visualViewport?.width ?? 0).toDouble(),
          (window.visualViewport?.height ?? 0).toDouble()));
    });
  }
  Size get size => Size((window.visualViewport?.width ?? 0).toDouble(),
      (window.visualViewport?.height ?? 0).toDouble());
  Offset get scroll => Offset(
      (window.visualViewport?.offsetLeft ?? 0).toDouble(),
      (window.visualViewport?.offsetTop ?? 0).toDouble());
}

the resize event is fired when keyboard appears

@alvarogabrielgomez
Copy link

any update?

@MisterJimson
Copy link
Owner Author

No, the web plugin is still a stub. I have not found a reliable implementation.

@lucasdealmeida91
Copy link

i have some problems with phone with android version 9, dont work

@chentianxin
Copy link

chentianxin commented Jun 6, 2024

There is a non-standard method that can be used on higher versions of Android
mdn link
chrome link
caniuse link

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

No branches or pull requests

8 participants