Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/f-person/flutter_persistent_keyboard_height
Flutter package to get keyboard height. Can be used to display a sticker/emoji modal with correct height.
https://github.com/f-person/flutter_persistent_keyboard_height
dart dart-package flutter flutter-package keyboard-height
Last synced: 24 days ago
JSON representation
Flutter package to get keyboard height. Can be used to display a sticker/emoji modal with correct height.
- Host: GitHub
- URL: https://github.com/f-person/flutter_persistent_keyboard_height
- Owner: f-person
- License: mit
- Created: 2021-09-04T14:45:41.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-13T17:00:58.000Z (over 2 years ago)
- Last Synced: 2024-10-03T09:28:11.540Z (about 1 month ago)
- Topics: dart, dart-package, flutter, flutter-package, keyboard-height
- Language: Dart
- Homepage: https://pub.dev/packages/flutter_persistent_keyboard_height
- Size: 415 KB
- Stars: 14
- Watchers: 3
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_persistent_keyboard_height [![Pub version](https://img.shields.io/pub/v/flutter_persistent_keyboard_height.svg)](https://pub.dev/packages/flutter_persistent_keyboard_height)
Flutter package to get keyboard height. The height is persisted during app
sessions and keyboard states (you can use the height when keyboard is closed).![](https://github.com/f-person/flutter_persistent_keyboard_height/blob/master/doc/demo.gif?raw=true)
## Usage
#### Registering the provider
First thing you need to do is wrap a widget from children of which you want
to get the keyboard height with `PersistentKeyboardHeightProvider`.
Add it to the `builder` of your app widget (perhaps `MaterialApp`) if you
want to get keyboard height from all widgets.```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Persistent Keyboard Height Example',
home: const FlutterPersistentKeyboardHeightExample(),
builder: (context, child) => PersistentKeyboardHeightProvider(
child: child!,
),
);
}
}
```#### Getting the keyboard height
In order to get keyboard height use the `PersistentKeyboardHeight`
inherited widget:
```dart
Widget build(BuildContext context) {
final keyboardHeight = PersistentKeyboardHeight.of(context).keyboardHeight;return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.all(16.0),
child: TextField(
decoration: InputDecoration(
labelText: 'Flutter Persistent Keyboard Size Example',
),
),
),
const SizedBox(height: 8),
Text('Keyboard height: $keyboardHeight'),
],
),
);
}
```#### Using a custom storage provider
By default, the package uses `shared_preferences` to preserve the keyboard
height but if you want to use a custom solution for preserving the height
you can do that by implementing the `IPersistentKeyboardHeightStorageProvider`
interface and passing an instance of the class to `PersistentKeyboardHeightProvider`:
```dart
class CustomPersistentKeyboardHeightStorageProvider
implements IPersistentKeyboardHeightStorageProvider {
const CustomPersistentKeyboardHeightStorageProvider();@override
Future getHeight() {
// read the height from storage
}@override
Future setHeight(double height) {
// save the height to storage
}
}class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Persistent Keyboard Height Example',
home: const FlutterPersistentKeyboardHeightExample(),
builder: (context, child) => PersistentKeyboardHeightProvider(
child: child!,
),
);
}
}
```---
Check out the `example` directory for a complete example app.
## The development process
The first version of this package was developed in two livestreams.
Unfortunately, my voice disappeared at the middle of the first livestream but
the second livestream is okay. In case you want to check them out, here are the links:
[Part 1](https://www.youtube.com/watch?v=Ezks4Ae8rxI),
[Part 2](https://www.youtube.com/watch?v=eude8Ht9bNI).## Thanks to
* The [keyboard_utils](https://github.com/IsaiasSantana/keyboard_utils) package.