keyboard_insets 0.1.0
keyboard_insets: ^0.1.0 copied to clipboard
A Flutter plugin that provides real-time keyboard height and visibility state across platforms.
π¦ Keyboard Insets #
A Flutter plugin that provides real-time keyboard insets and visibility state across iOS and Android.
Unlike MediaQuery.viewInsets, this package gives you frame-by-frame updates from the native views without relying on BuildContext.
β¨ Features #
- Real-time keyboard height stream
- Keyboard state stream (visibility + animation status)
- Persistent safe area support (bottom insets independent of keyboard)
- Automatic lifecycle: native observers start/stop based on active listeners
- Lightweight, FFI-based (no MethodChannels)
π¦ Installation #
Add the package to your pubspec.yaml:
dependencies:
keyboard_insets: ^0.1.0
iOS Setup #
Make sure your iOS deployment target is at least 13.0
Open ios/Podfile and set:
platform :ios, '13.0'
βοΈ Platform Details #
| Platform | Implementation | Notes |
| iOS | CASpringAnimation |
Requires iOS 13.0+ |
| Android | WindowInsetsAnimationCompat + FFI |
Reads per-frame inset updates |
| Web | Uses visualViewport.onresize |
Lightweight JavaScript interop |
| Desktop | Dummy implementation | Always returns zero insets |
π Usage #
Keyboard Height #
KeyboardInsets.insets.listen((height) {
print('Keyboard height: $height');
});
Keyboard State #
KeyboardInsets.stateStream.listen((state) {
print('Visible: ${state.isVisible}, Animating: ${state.isAnimating}');
});
Persistent Safe Area Bottom #
To listen to bottom safe area (home indicator / navigation bar) height, which stays constant during keyboard animations:
PersistentSafeAreaBottom.startObservingSafeArea();
print('Safe area bottom: ${PersistentSafeAreaBottom.notifier.value}');
PersistentSafeAreaBottom.stopObservingSafeArea();
π§± Widgets #
π¦ PersistentSafeArea #
A drop-in replacement for Flutterβs SafeArea that preserves bottom padding even when the keyboard opens or closes.
PersistentSafeArea(
child: Scaffold(
body: Center(child: Text("I ignore keyboard changes!")),
),
)
||||
--|--|--|--
Name|Type|Description
child|Widget|The widget below this safe area.
handleObserver|bool|Whether to automatically start/stop the native safe area observer. If set to false you must manage it manually. Defaults to false.
The bottom safe area padding stays stable while the keyboard animates, and only updates when the system safe area itself changes (like orientation rotation or system UI change).
π API Reference #
Keyboard Insets #
||||
--|--|--|--
API|Type|Description
KeyboardInsets.insets|Stream<double>|Real-time keyboard height (px)
KeyboardInsets.stateStream|Stream<KeyboardState>|Visibility + animation state
KeyboardInsets.keyboardHeight|double|Persistent keyboard height
KeyboardInsets.isVisible|bool|Whether the keyboard is visible
KeyboardInsets.isAnimating|bool|Whether keyboard is animating
π€ Contribution #
Contributions are welcome! Please open issues for bugs or feature requests. Submit pull requests with clear descriptions and tests.
See CONTRIBUTING.md for guidelines.
π License #
BSD-2 License. See LICENSE for details.