搜尋套件、儲存庫與 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

原始碼儲存庫

使用此套件的專案