MisterJimson / flutter_keyboard_visibility

Get notified on keyboard visibility changes in your Flutter app
MIT License
393 stars 105 forks source link

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

Open MisterJimson opened 4 years ago

MisterJimson commented 4 years ago

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.

otopba commented 3 years ago

Any updates?

MisterJimson commented 3 years ago

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

esase commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 1 year ago

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 commented 1 year ago

@cmaccarone can you link to documentation for those events?

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

cmaccarone commented 1 year ago

@MisterJimson see my edits

MisterJimson commented 1 year ago

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 commented 1 year ago

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 commented 4 months ago

any update?

MisterJimson commented 4 months ago

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

lucasdealmeida91 commented 4 weeks ago

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

chentianxin commented 4 weeks ago

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