Compare commits
No commits in common. "76de3403ebab8a875bc0446c2d4dd93172c75f93" and "4f4a551217165f61a65f46a47168d265c1de6636" have entirely different histories.
76de3403eb
...
4f4a551217
15
CHANGELOG.md
15
CHANGELOG.md
@ -1,16 +1,3 @@
|
||||
## 0.0.1
|
||||
|
||||
* Initial release.
|
||||
|
||||
## 0.0.2
|
||||
|
||||
* Documentation.
|
||||
|
||||
## 0.0.3
|
||||
|
||||
* More documentation.
|
||||
|
||||
## 0.0.4
|
||||
|
||||
* N/A
|
||||
|
||||
* TODO: Describe initial release.
|
||||
|
30
LICENSE
30
LICENSE
@ -1,29 +1 @@
|
||||
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.
|
||||
TODO: Add your license here.
|
||||
|
64
README.md
64
README.md
@ -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
|
||||
dependencies:
|
||||
keyboard_height_plugin: ^0.0.4
|
||||
```
|
||||
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.
|
||||
|
||||
## 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).
|
||||
# keyboard_height_plugin
|
||||
|
@ -1,76 +1,63 @@
|
||||
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(MyApp());
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: HomePage(),
|
||||
);
|
||||
}
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
@override
|
||||
_HomePageState createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
double _keyboardHeight = 0;
|
||||
final KeyboardHeightPlugin _keyboardHeightPlugin = KeyboardHeightPlugin();
|
||||
class _MyAppState extends State<MyApp> {
|
||||
String _platformVersion = 'Unknown';
|
||||
final _keyboardHeightPlugin = KeyboardHeightPlugin();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_keyboardHeightPlugin.onKeyboardHeightChanged((double height) {
|
||||
setState(() {
|
||||
_keyboardHeight = height;
|
||||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Keyboard Height'),
|
||||
title: const Text('Plugin example app'),
|
||||
),
|
||||
body: Center(
|
||||
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',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text('Running on: $_platformVersion\n'),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import 'package:flutter/services.dart';
|
||||
typedef KeyboardHeightCallback = void Function(double height);
|
||||
|
||||
class KeyboardHeightPlugin {
|
||||
static const EventChannel _keyboardHeightEventChannel = EventChannel('keyboardHeightEventChannel');
|
||||
static const EventChannel _keyboardHeightEventChannel = const EventChannel('keyboardHeightEventChannel');
|
||||
|
||||
StreamSubscription? _keyboardHeightSubscription;
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
name: keyboard_height_plugin
|
||||
description: Flutter plugin that emits keyboard height before it shows (ios/android)
|
||||
version: 0.0.4
|
||||
repository: https://github.com/nschairer/keyboard_height_plugin
|
||||
description: A new Flutter plugin project.
|
||||
version: 0.0.1
|
||||
homepage:
|
||||
|
||||
environment:
|
||||
sdk: '>=2.18.0 <3.0.0'
|
||||
sdk: '>=2.19.6 <3.0.0'
|
||||
flutter: ">=2.5.0"
|
||||
|
||||
dependencies:
|
||||
|
Loading…
Reference in New Issue
Block a user