パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.0

flutter_focus_watcher

新しいFlutterパッケージ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
290
いいね数
23
Pub ポイント
140

パッケージをインストール

flutter pub add flutter_focus_watcher

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutter Focus Watcher は、ウィジェットのフォーカス変更を監視するように設計された Flutter パッケージであり、特にフォーム処理に役立ちます。開発者は、ウィジェットがフォーカスを得たり失ったりしたときに検出でき、フォーカスされたフィールドのハイライトやバリデーションのトリガーなどの応答性のある UI 挙動を実現できます。このパッケージは、Android、iOS、Web、macOS、Windows、Linux などすべての主要プラットフォームをサポートしており、クロスプラットフォームアプリに最適です。pub add を使用した最小限の設定で、既存のフォームや入力ワークフローにシームレスに統合できます。

用途

  • フォーム内のフォーカス状態をモニタリングする
  • フォーカス変更時に検証をトリガーする
  • フォーカスフィードバックによるアクセシビリティの向上
  • フォーカスに基づいた動的UIの更新を実装する
  • ユーザーのインタラクションパターンのトラッキング
  • 複雑な入力におけるフォームの使いやすさの向上

主な機能

  • リアルタイムでのフォーカス変更検出
  • クロスプラットフォーム互換性
  • 既存のウィジェットとの簡単な統合
  • フォーカスの取得および喪失イベントをサポートします
  • 軽量で効率的
  • テキストフィールドおよびカスタムフォーカス可能なウィジェットと連携可能

適している対象

  • フォーム中心のアプリケーション
  • アクセシビリティを重視した開発
  • インタラクティブUIコンポーネント
  • クロスプラットフォームモバイルおよびWebアプリ
  • リアルタイムの入力フィードバックを求める開発者
  • 高度なフォーム状態管理を必要とするアプリ

注意事項

  • 複雑なシナリオではフォーカス状態を手動で処理する必要があります
  • ネストされたまたは動的なフォームに対応するための追加ロジックが必要になる可能性があります
  • フォーム以外の用途には想定されていません
  • フォーカス関連イベントに限定
  • 他のフォーム検証パッケージと併用するのが最適です
  • パフォーマンスへの影響は無視できるが、大規模なフォームではテストする必要がある

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Flutter Focus Watcher

This widget is used to remove TextField focus if a tap occured somewhere else In order for this to work properly, it must be placed inside MaterialApp or WidgetsApp. This is necessary because this widget requires MediaQuery, which is supplied by those two.

The widget also keeps track of a keyboard space and moves the whole application up if a focused TextField gets obscured by the keyboard The only additional thing you need to do for it is to set your Scaffold's resizeToAvoidBottomInset to false (in case you use scaffold) and that's it. If you want to change the height of application lift, simply set your preferred value to the FocusWatcher's liftOffset variable. The default value is 15.0. This means the number of points above the keyboard's upper bound

Example

It's very easy to use. You may add it as a library or simply copy flutter_focus_watcher.dart into your project. It doesn't have any external dependencies

Then simply do this. Notice that FocusWatcher is inside MaterialApp. That's because it inherits MediaQuery from that

IMPORTANT! You must wrap with the FocusWatcher every scaffold where you want this functionality

import 'package:flutter/material.dart';
import 'package:flutter_focus_watcher/flutter_focus_watcher.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
   Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Demo app',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Demo Home Page')
      );
    }
}

 @override
  Widget build(BuildContext context) {
    return FocusWatcher(
        child: Scaffold(
         // don't forget about this
         resizeToAvoidBottomInset: false,
         ...
       )
    );
     
  }

And it will do the rest.

alt watcher

And here is how it handles the keyboard

alt keyboard

In case you want to exclude some widget from this workflow, simply wrap that widget with

@override
Widget build(BuildContext context) {
    return IgnoreFocusWatcher(
      child: TextField("I will be ignored by FocusWatcher")
    );
}

And this widget will be ignored by FocusWatcher

There may also be some cases when a TextField (like material text field) does not apply a RenderEditable or RenderParagraph thus making this plugin useless. You can simply fix it by wrapping the TextField in a ForceFocusWatcher() widget. That's it

@override
Widget build(BuildContext context) {
    return ForceFocusWatcher(
      child: TextField("I'm forced to activate focus watcher")
    );
}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。