Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Keyboard Detect Visibility

Tags:

flutter

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

like image 410
John Gorter Avatar asked Dec 10 '25 22:12

John Gorter


1 Answers

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);
    },
  );
}
like image 128
Harsh Bhikadia Avatar answered Dec 12 '25 21:12

Harsh Bhikadia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!