简体   繁体   中英

Flutter Keyboard Detect Visibility

I want to detect if the keyboard is visible. I could implement the hacks that were suggested on other stackoverlfow threads:

bool keyboardvisible = MediaQuery.of(context).viewInsets.bottom > 0;

and this works for Android, but on iOS this bottom property always seems to return 0, no matter if the keyboard is visible or not.

Is there any better approach to detect keyboard visibility that actually works on both platforms?

Thnx John

this plugin will help you. It provides a listener for visibility change for both iOS and Android.

Example Code:

import 'package:keyboard_visibility/keyboard_visibility.dart';

@protected
void initState() {
  super.initState();

  KeyboardVisibilityNotification().addNewListener(
    onChange: (bool visible) {
      print(visible);
    },
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM