搜索插件、代码仓与 APP 分类

插件详情v0.3.0

keyboard_height_plugin

在显示之前发出键盘高度的 Flutter 插件(iOS/Android)

AndroidiOS
近 30 天下载
4.1万
喜欢数
31
Pub 分数
150

安装插件

flutter pub add keyboard_height_plugin

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

keyboard_height_plugin 是一个 Flutter 包,可在 Android 和 iOS 设备上实时更新屏幕键盘在出现前的高度。它会在键盘即将显示时发出键盘高度信息,使开发者能够动态调整 UI 布局,从而提升用户体验。该插件特别适用于表单或输入字段,避免内容被键盘遮挡。它在两个主要移动平台上都能无缝运行,并可通过 pub.dev 轻松集成。该插件轻量且专注于键盘高度检测,不包含额外功能。

适合场景

  • 动态表单布局调整
  • 防止输入字段重叠
  • 实时UI响应性
  • 移动应用键盘意识
  • 优化输入过程中的屏幕空间

主要特点

  • 在显示前发出键盘高度
  • 跨平台(Android & iOS)
  • 轻量且专注
  • 通过 pub.dev 的简单集成
  • 无额外依赖

适合对象

  • 开发输入密集型应用的开发者
  • 需要响应式 UI 的应用
  • 基于表单的移动应用
  • 需要精确键盘反馈的项目
  • 针对 iOS 和 Android 的 Flutter 应用

使用建议

  • 需要手动处理布局变化
  • 仅限键盘高度
  • 不支持自定义键盘
  • 无内置动画支持
  • 可能需要额外的状态管理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Keyboard Height Plugin for Flutter

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.

Requirements

Version 0.3.0+ (Current)
  • Android:
    • Android Gradle Plugin (AGP) 8.6.0+
    • Gradle 8.7+
    • Kotlin 2.1.0+
    • Java 17+
    • minSdkVersion 16 (Android 4.1+)
    • compileSdkVersion 34+
  • iOS:
    • iOS 12.0+
    • Supports both CocoaPods and Swift Package Manager
    • Includes Privacy Manifest for App Store compliance
Version 0.1.5 (Legacy Support)

For projects that cannot upgrade to the modern build tools, use version 0.1.5:

  • Android Gradle Plugin 7.x
  • Kotlin 1.7.x
  • Java 11+

Installation

To install keyboard_height_plugin, add it to your pubspec.yaml file under the dependencies section:

dependencies:
  keyboard_height_plugin: ^0.3.0

For legacy projects:

dependencies:
  keyboard_height_plugin: 0.1.5

Usage

To use the keyboard_height_plugin, first import it in your Dart file:

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:

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:

@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 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.

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目