XKeyboard class

Frame-accurate keyboard height tracking for iOS and Android.

Reads the keyboard position directly from the native layer via FFI each frame, bypassing Flutter's MediaQuery.viewInsets which lags behind.

Supports interactive dismiss (swipe-to-dismiss like iMessage) and provides sampled native animation curves with adaptive learning.

Use the singleton instance and listen for changes via addListener:

final keyboard = XKeyboard.instance;
keyboard.enableInteractiveDismiss(trackingInset: 56);

First access to instance registers a persistent frame callback and, on Android, a method call handler — both require an initialized Flutter binding, so touch it only after runApp (or an explicit WidgetsFlutterBinding.ensureInitialized()).

Mixed-in types
Available extensions

Constructors

XKeyboard.test({required double nativeHeight(), int isTracking()?, double animTarget()?, double animDuration()?, int animGen()?, double devicePixelRatio = 1.0})
A keyboard with injected native readers — under flutter test the FFI symbols never resolve, so instance cannot exercise the frame loop. Registers no frame callback; drive it with debugFrame.

Properties

hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
height → double
The current keyboard height in logical pixels, snapped to the physical pixel grid.
no setter
isOpen → bool
Whether the keyboard is currently visible.
no setter
isTracking → bool
Whether an interactive dismiss pan gesture is active.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
systemHeight → double
The last system-reported keyboard height.
no setter
windowFocusCounter → ValueNotifier<int>
Increments each time the native window gains input focus — the signal Android needs before the IME can be raised. Listen for changes when you want to re-trigger a pending focus request at cold start (e.g. a TextField(autofocus: true) whose initial TextInput.show was dropped because the window wasn't yet focused).
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
debugFrame(Duration timestamp) → void
Runs one frame of the reader loop.
didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
inherited
didChangeAppLifecycleState(AppLifecycleState state) → void
Called when the system puts the app in the background or returns the app to the foreground.
inherited
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
inherited
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
override
didChangePlatformBrightness() → void
Called when the platform brightness changes.
inherited
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
inherited
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
inherited
didHaveMemoryPressure() → void
Called when the system is running low on memory.
inherited
didPopRoute() → Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
inherited
didPushRoute(String route) → Future<bool>
Called when the host tells the application to push a new route onto the navigator.
inherited
didPushRouteInformation(RouteInformation routeInformation) → Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
inherited
didRequestAppExit() → Future<AppExitResponse>
Called when a request is received from the system to exit the application.
inherited
disableInteractiveDismiss() → void
Disables the swipe-to-dismiss gesture.
dispose() → void
Discards any resources used by the object.
inherited
enableInteractiveDismiss({double trackingInset = 0}) → void
Enables swipe-to-dismiss on the keyboard.
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
inherited
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
inherited
handleStartBackGesture(PredictiveBackEvent backEvent) → bool
Called at the start of a predictive back gesture.
inherited
handleStatusBarTap() → void
Called when the user taps the status bar on iOS, to scroll a scroll view to the top.
inherited
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
subscribe(VoidCallback callback) → VoidCallback

Available on Listenable, provided by the ListenableExtension extension

Adds callback as listener and returns a function to remove it.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

instance → XKeyboard
The singleton instance.
final

Static Methods

clampPrediction({required double h, required double native, required double animFrom, required double animTo, required double current}) → double
Caps the LUT prediction h against the fresh native reading. The native value is per-vsync fresh on Android R+ (via WindowInsetsAnimation.onProgress) and iOS (via CADisplayLink); on Android pre-R it snaps to the target up-front, making this a no-op. This trades the LUT's predictive lead for robustness against overshoot when the LUT hasn't adapted to this device's actual curve.
snapToPixelGrid(double h, double devicePixelRatio) → double
h on the physical-pixel grid of devicePixelRatio. Readings within the same physical pixel collapse to one published value, so listeners never see sub-pixel churn.