Compare commits

...

10 Commits

Author SHA1 Message Date
76de3403eb Reduce the Dart SDK requirements 2023-05-16 23:35:02 +02:00
Noah Schairer
7accb1c1de
Update README.md 2023-04-28 16:51:49 -04:00
Noah Schairer
5392f97926 remove carrots from license 2023-04-28 16:23:43 -04:00
Noah Schairer
6ddc51bea8 license fix 2023-04-28 16:21:12 -04:00
Noah Schairer
0f34339911 changelog 2023-04-28 16:14:17 -04:00
Noah Schairer
938d5af3b8 0.0.2 2023-04-28 16:13:15 -04:00
Noah Schairer
a6d7219992
Update README.md 2023-04-28 16:12:19 -04:00
Noah Schairer
d2495eb653 license stuff 2023-04-28 16:10:30 -04:00
Noah Schairer
8a354c6765 updated example 2023-04-28 15:59:37 -04:00
Noah Schairer
89745f163e published 0.0.1 2023-04-28 15:31:57 -04:00
6 changed files with 155 additions and 59 deletions

View File

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

30
LICENSE
View File

@ -1 +1,29 @@
TODO: Add your license here.
BSD 3-Clause License
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,16 +1,58 @@
# keyboard_height_plugin
# Keyboard Height Plugin for Flutter
A new Flutter plugin project.
`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.
## Getting Started
## Installation
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.
To install `keyboard_height_plugin`, add it to your `pubspec.yaml` file under the `dependencies` section:
For help getting started with Flutter development, view the
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
```yaml
dependencies:
keyboard_height_plugin: ^0.0.4
```
# keyboard_height_plugin
## Usage
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,63 +1,76 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:keyboard_height_plugin/keyboard_height_plugin.dart';
void main() {
runApp(const MyApp());
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
class MyApp extends StatelessWidget {
@override
State<MyApp> createState() => _MyAppState();
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _keyboardHeightPlugin = KeyboardHeightPlugin();
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double _keyboardHeight = 0;
final KeyboardHeightPlugin _keyboardHeightPlugin = KeyboardHeightPlugin();
@override
void initState() {
super.initState();
initPlatformState();
}
// 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;
_keyboardHeightPlugin.onKeyboardHeightChanged((double height) {
setState(() {
_keyboardHeight = height;
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text('Plugin example app'),
title: Text('Keyboard Height'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
child: Stack(
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);
class KeyboardHeightPlugin {
static const EventChannel _keyboardHeightEventChannel = const EventChannel('keyboardHeightEventChannel');
static const EventChannel _keyboardHeightEventChannel = EventChannel('keyboardHeightEventChannel');
StreamSubscription? _keyboardHeightSubscription;

View File

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