搜尋套件、儲存庫與 APP 分類

套件詳情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 項

原始碼儲存庫

使用此套件的專案