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

パッケージ詳細v0.0.2

defer_pointer

親の境界外に簡単にウィジェットをレンダリングおよびヒットテストできる、Overlayの代替です。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
8万
いいね数
158
Pub ポイント
130

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

flutter pub add defer_pointer

パッケージ概要

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

defer_pointer パッケージは Flutter の Overlay の代替を提供し、ウィジェットが親ウィジェットの境界外でレンダリングおよび操作できるようにします。UI インフラストラクチャ内で動的に配置されたウィジェットのヒットテストを簡素化し、複雑なオーバーレイ、ツールチップ、またはレイアウト制約に関係なくポインターイベントに応答する必要があるフローティング要素に最適です。gskinner.com によって開発され、Android、iOS、Web、macOS、Windows、Linux を含むすべての主要プラットフォームをサポートしています。このパッケージは手動でのレイヤー管理を必要とせずに、ユーザーインタラクションの柔軟性を向上させます。

用途

  • 浮遊ツールチップの作成
  • ダイナミックなオーバーレイの構築
  • 制限付きレイアウトでのドラッグアンドドロップの実装
  • 親の境界を超えるインタラクティブ要素のレンダリング
  • カスタムポインター対応UIコンポーネントの設計

主な機能

  • 境界をまたぐヒットテストをサポート
  • オーバーレイの実装を簡素化します
  • すべての Flutter プラットフォームで動作します
  • 最小限のボイラープレートが必要
  • 既存のウィジェットツリーにスムーズに統合されます

適している対象

  • 複雑なUIインタラクションを構築する開発者
  • 応答性のオーバーレイが必要なチーム
  • 動的なフローティング要素を備えたアプリ
  • 高度なポインター処理を必要とするUIライブラリ
  • 複数のプラットフォームをターゲットにするプロジェクト

注意事項

  • 多数のアクティブなウィジェットがあるとパフォーマンスに影響する可能性があります
  • 状態管理に注意が必要です
  • 単純な静的オーバーレイには適していません
  • 基本的な使用方法以外のドキュメントは限られている
  • 適切に管理されない場合、意図しないポインターのキャプチャが発生する可能性がある

元の README

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

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds. Based on the original idea by @shrouxm here: https://github.com/flutter/flutter/issues/75747#issuecomment-907755810

Typically in Flutter, if you offset a widget outside of it's parent bounds hit-testing will break. DeferPointer works around this issue by handing off hit-testing and (optionally) rendering to an DeferredPointerHandler widget further up the tree.

While Overlay can solve this issue to some degree, using DeferPointer offers some benefits:

  • just works: no error prone and tedious layer management
  • more granular: you can set the bounds to be any ancestor widget you choose
  • more flexible: you can choose to paint the child on top, or not
  • easier to align/pin to a widget in the tree as that is the default expectation

This is useful for larger UI components like dropdown menus and sliding panels, as well as just small general styling tweaks.

🔨 Installation

dependencies:
  defer_pointer: ^0.0.2
⚙ Import
import 'package:defer_pointer/defer_pointer.dart';

🕹️ Usage

  1. Wrap a DeferredPointerHandler somewhere above the buttons that you wish to hit-test.
  2. Wrap DeferPointer around the buttons themselves.
Widget build(BuildContext context) {
    return DeferredPointerHandler(
       child: SizedBox(
           width: 100,
           height: 100,
           child: Stack(clipBehavior: Clip.none, children: [
             // Hang button off the bottom of the content
             Positioned(
               bottom: -30,
               child: DeferPointer(child: _SomeBtn(false)),
             ),
             // Content
             Positioned.fill(
               child: Container(
                 decoration: BoxDecoration(color: Colors.green, boxShadow: [
                   BoxShadow(color: Colors.black.withOpacity(1), blurRadius: 4, spreadRadius: 4),
                 ]),
               ),
             ),
           ]))));
  }

Enable paintOnTop if you need the child Widget painted on top of it's siblings. This will defer painting to the currently linked DeferredPointerHandler.

return DeferPointer(
    paintOnTop: true,
    child: TextButton(...));
Examples

There are 4 examples in this repo:

  1. A simple example of offsetting 2 buttons outside their stack: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/simple_offset_outside_parent.dart

  2. A classic desktop/web style dropdown menu: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/dropdown_menus.dart

  3. A animated menu based on the Flow widget: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/flow_menu.dart

  4. A auto-complete search field: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/auto_complete.dart

Manual Linking

By default a DeferPointer widget will look up the closest DeferredPointerHandler using it's current context. For more complicated use cases you can manually assign a link to bind a pointer to a handler:

final _deferredPointerLink = DeferredPointerHandlerLink();
...
Widget build(){
    return DeferredPointerHandler(
      link: _deferredPointerLink,
      child: Padding(
          padding: const EdgeInsets.all(20),
          child: DeferPointer(
            link: _deferredPointerLink,
            child: ...,
          )),
    );
}

🐞 Bugs/Requests

If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.

📃 License

MIT License

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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