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

measure_size のカバー
パッケージ詳細v5.0.2

measure_size

サイズが変更されたときにコールバックをトリガーするウィジェット

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.5万
いいね数
40
Pub ポイント
160

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

flutter pub add measure_size

パッケージ概要

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

measure_size パッケージは、サイズが変更されたときにコールバックをトリガーする Flutter ウィジェットであり、実際のレンダリングされた寸法に基づいて動的なレイアウト調整を可能にします。このパッケージは子ウィジェットをラップし、ビルドおよびレイアウトフェーズ中にそのサイズを監視し、応答性のあるデザインや正確な測定値に依存するアニメーションに最適です。このパッケージは、Android、iOS、Web、macOS、Windows、Linux などのすべての主要プラットフォームで動作し、一貫した振る舞いを保証します。固定値に頼らずにコンテナサイズの変化に反応したい場合に特に役立ちます。

用途

  • 動的サイズ調整を備えたレスポンシブUI
  • ウィジェットの寸法に基づくアニメーション
  • レイアウトのデバッグ
  • 動的コンテンツのレンダリング
  • リアルタイムサイズモニタリング

主な機能

  • サイズ変更時にコールバックをトリガーします
  • クロスプラットフォーム互換性
  • 既存のウィジェットとの簡単な統合
  • すべての Flutter プラットフォームをサポートしています
  • 外部の依存関係なし

適している対象

  • リアルタイムのサイズフィードバックが必要な開発者
  • 適応型レイアウトを必要とするUIコンポーネント
  • レイアウトの問題のテストとデバッグ
  • 動的または流動的なデザインシステムを持つプロジェクト

注意事項

  • 過剰に使用するとパフォーマンスに影響を与える可能性があります
  • レイアウト中にコールバックが複数回発火する可能性があります
  • 固定サイズの要件には適していません
  • 複雑なウィジェットツリーでは注意深く扱う必要がある
  • サイズの変更に限定され、位置やオフセットは対象外

元の README

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

measure_size

A Flutter package for efficiently measuring widget sizes and building size-aware, adaptive layouts with minimal overhead.


Measuring text and drawing an overlay with matching size


MeasureSize MeasureSizeBuilder
Purpose Monitor size changes Prototype-driven layout
Callback timing Post-frame During layout (invokeLayoutCallback)
Measurements Single widget Multiple prototypes
Use case Reactive to size changes Proactive layout decisions
Complexity Simple Advanced
Performance Good Excellent (single pass)
PreferredSizeWidget limitation Does not work First frame problematic

import 'package:measure_size/measure_size.dart';

Widget child = Text('Lorem ipsum dolor sit amet');

MeasureSize(
    onChange: (Size newSize) {
        /// [newSize] will be the displayed size of [Widget child]
    },
    child: child,
);

MeasureSizeBuilder<String>(
    prototypeConstraints: (constraints) => BoxConstraints(
      minWidth: 0,
      maxWidth: constraints.maxWidth,
      minHeight: 0,
      maxHeight: double.infinity,
    ),
    prototypes: [
      PrototypeId(
        id: 'lorem',
        child: child,
      ),
    ],
    builder: (context, sizes) {
      // [sizes['lorem']] will be the layed out size of [Widget child]
      return child;
    }
);

MeasureSize

Required
  • Widget child - This widget will be displayed and and measured.
Optional
  • void onChange(Size newSize) - A callback that is fired exactly once after the first frame of the child widget is rendered.

MeasureSizeBuilder<T>

Required
  • List<PrototypeId<T>> prototypes - Wrap widgets you'd like to measure with PrototypeId and provide a unique identifier for each widget.
  • PrototypeWidgetBuilder<T> builder - A builder function that contains the sizes of all prototypes.
  • PrototypeConstraintCalculator prototypeConstraints - Constraints to be assigned to each prototype widget.

Example

A demonstration can be found in the example directory. To run the example:

flutter run example/main.dart

Credits

カテゴリー

ソースリポジトリ

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