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

パッケージ詳細v1.0.0+4

sized_context

コンテキスト上でMediaQueryのサイズ情報を直接アクセスし、サイズやレイアウト用のヘルパー関数も追加します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
60
いいね数
195
Pub ポイント
160

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

flutter pub add sized_context

パッケージ概要

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

sized_context パッケージは、コンテキストを通じて MediaQuery のサイズ情報に直接アクセスできるようにし、レスポンシブUI開発を簡略化します。このパッケージは、画面メトリクスに基づいてサイズ、余白、レイアウト寸法を計算するための便利なヘルパー関数をBuildContextに拡張します。これにより、ウィジェットツリー全体でMediaQuery.of(context)を繰り返し呼び出す必要がなくなります。さまざまなデバイスサイズおよび向きに対応する柔軟なレイアウト構築に最適です。

用途

  • レスポンシブレイアウトデザイン
  • クロスプラットフォームUIの適応
  • ダイナミックウィジェットサイズ調整
  • MediaQuery の使用を簡素化する
  • デバイス間の一貫した間隔

主な機能

  • コンテキストに基づく直接サイズ指定
  • 組み込みのサイズ計算ヘルパー
  • ボイラープレートコードを削減する
  • すべてのFlutterプラットフォームをサポートしています
  • 既存のウィジェットとの簡単な統合

適している対象

  • 応答性のあるアプリを開発する開発者
  • UIの一貫性を重視するチーム
  • 複数のプラットフォームをターゲットにするプロジェクト
  • 動的レイアウトを必要とするアプリ

注意事項

  • コンテキストアクセスが必要です
  • 過剰に使用するとビルドの複雑さが増す可能性があります
  • シンプルな静的レイアウトには不要
  • サイズ関連機能に限定
  • 他のレイアウトパッケージと併用するのが最適です

元の README

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

✥ Sized Context - Easy responsive sizing

With this extension package you can easily access the MediaQuery sizing info directly on the build context:

Size size = context.sizePx;

It also provides additional convenience methods like landscape state, diagonal screen size, inch-based measurements, screen type and percentage values:

bool isLandscape = context.isLandscape; //Instead of: MediaQuery.of(context).orientation == Orientation.landscape
bool isTablet = context.diagonalInches >= 7; //Get physical device size in inches 
bool useSingleColumn = context.widthPx < 400; //Access .width and .height directly, no need to go through .size
double sidePadding = context.widthPercent(0.1); //Use percentages of width or height for sizing

🔨 Installation

dependencies:
  sized_context: ^1.0.0+1
⚙ Import
import 'package:sized_context/sized_context.dart';

🕹️ Usage

bool isLandscape = context.isLandscape;
//PIXELS
Size size = context.sizePx;
double width = context.widthPx;
double height = context.heightPx;
double diagonalPx = context.diagonalPx;
//INCHES
Size sizeInInches = context.sizeInches;
double widthInInches = context.widthInches;
double heightInInches = context.heightInches;
double diagonalInInches = context.diagonalInches;
//PERCENTAGE
double widthPercent = context.widthPct(.1);
double heightPercent = context.heightPct(.25);

For convenience you can also access the MediaQueryData object directly, to get any other methods or properties:

EdgeInsets padding = context.mq.padding;
Size safeSize = context.mq.removePadding();

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

👏 Thanks

  • Thanks to reddit user der_kobold for the idea to turn this into an extension!

📃 License

MIT License

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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