Compare commits

..

No commits in common. "76de3403ebab8a875bc0446c2d4dd93172c75f93" and "4f4a551217165f61a65f46a47168d265c1de6636" have entirely different histories.

6 changed files with 59 additions and 155 deletions

View File

@ -1,16 +1,3 @@
## 0.0.1 ## 0.0.1
* Initial release. * TODO: Describe initial release.
## 0.0.2
* Documentation.
## 0.0.3
* More documentation.
## 0.0.4
* N/A

30
LICENSE
View File

@ -1,29 +1 @@
BSD 3-Clause License TODO: Add your license here.
Copyright (c) 2023, Noah Schairer
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,58 +1,16 @@
# Keyboard Height Plugin for Flutter # keyboard_height_plugin
`keyboard_height_plugin` is a Flutter plugin for iOS and Android that provides the keyboard size before the keyboard animation occurs for showing or hiding it. This helps eliminate lag when positioning widgets around the keyboard, such as placing a TextField above the keyboard. A new Flutter plugin project.
## Installation ## Getting Started
To install `keyboard_height_plugin`, add it to your `pubspec.yaml` file under the `dependencies` section: This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
```yaml For help getting started with Flutter development, view the
dependencies: [online documentation](https://flutter.dev/docs), which offers tutorials,
keyboard_height_plugin: ^0.0.4 samples, guidance on mobile development, and a full API reference.
```
## Usage # keyboard_height_plugin
To use the `keyboard_height_plugin`, first import it in your Dart file:
```dart
import 'package:keyboard_height_plugin/keyboard_height_plugin.dart';
```
Next, create a stateful widget and declare a variable to store the keyboard height and create an instance of the `KeyboardHeightPlugin`:
```dart
class _HomePageState extends State<HomePage>; {
double _keyboardHeight = 0;
final KeyboardHeightPlugin _keyboardHeightPlugin = KeyboardHeightPlugin();
// ... rest of code ...
}
```
Then, initialize the `KeyboardHeightPlugin` in your `initState` method and listen for changes in the keyboard height:
```dart
@override
void initState() {
super.initState();
_keyboardHeightPlugin.onKeyboardHeightChanged((double height) {
setState(() {
_keyboardHeight = height;
});
});
}
```
Use the `_keyboardHeight` variable to position your widgets around the keyboard.
## Example
For a complete example on how to use the `keyboard_height_plugin`, please refer to the [`example`](example) directory in the repository.
## Contributing
If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on the project's GitHub repository.
## License
This plugin is licensed under the [BSD 3-Clause License](LICENSE).

View File

@ -1,76 +1,63 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:keyboard_height_plugin/keyboard_height_plugin.dart'; import 'package:keyboard_height_plugin/keyboard_height_plugin.dart';
void main() { void main() {
runApp(MyApp()); runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatefulWidget {
const MyApp({super.key});
@override @override
Widget build(BuildContext context) { State<MyApp> createState() => _MyAppState();
return MaterialApp(
home: HomePage(),
);
}
} }
class HomePage extends StatefulWidget { class _MyAppState extends State<MyApp> {
@override String _platformVersion = 'Unknown';
_HomePageState createState() => _HomePageState(); final _keyboardHeightPlugin = KeyboardHeightPlugin();
}
class _HomePageState extends State<HomePage> {
double _keyboardHeight = 0;
final KeyboardHeightPlugin _keyboardHeightPlugin = KeyboardHeightPlugin();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_keyboardHeightPlugin.onKeyboardHeightChanged((double height) { initPlatformState();
setState(() { }
_keyboardHeight = height;
}); // Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion =
await _keyboardHeightPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return MaterialApp(
resizeToAvoidBottomInset: false, home: Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Keyboard Height'), title: const Text('Plugin example app'),
), ),
body: Center( body: Center(
child: Stack( child: Text('Running on: $_platformVersion\n'),
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Keyboard height: $_keyboardHeight',
),
SizedBox(height: 16),
ElevatedButton(
child: Text('Get Keyboard Height'),
onPressed: () => {},
),
],
),
Positioned(
bottom: _keyboardHeight,
left: 0,
right: 0,
child: TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.orange,
hintText: 'Type here to open keyboard',
),
),
),
],
),
), ),
); ),
} );
}
} }

View File

@ -4,7 +4,7 @@ import 'package:flutter/services.dart';
typedef KeyboardHeightCallback = void Function(double height); typedef KeyboardHeightCallback = void Function(double height);
class KeyboardHeightPlugin { class KeyboardHeightPlugin {
static const EventChannel _keyboardHeightEventChannel = EventChannel('keyboardHeightEventChannel'); static const EventChannel _keyboardHeightEventChannel = const EventChannel('keyboardHeightEventChannel');
StreamSubscription? _keyboardHeightSubscription; StreamSubscription? _keyboardHeightSubscription;

View File

@ -1,10 +1,10 @@
name: keyboard_height_plugin name: keyboard_height_plugin
description: Flutter plugin that emits keyboard height before it shows (ios/android) description: A new Flutter plugin project.
version: 0.0.4 version: 0.0.1
repository: https://github.com/nschairer/keyboard_height_plugin homepage:
environment: environment:
sdk: '>=2.18.0 <3.0.0' sdk: '>=2.19.6 <3.0.0'
flutter: ">=2.5.0" flutter: ">=2.5.0"
dependencies: dependencies: