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

套件詳情v0.1.1

dimensions_theme

在 Flutter 主題中定義應用尺寸。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
148
喜歡數
24
Pub 分數
150

安裝套件

flutter pub add dimensions_theme

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

dimensions_theme 套件允許開發者在 Flutter 主題中直接定義和管理應用程式的尺寸,進而於不同螢幕尺寸上實現一致且響應式的 UI 設計。透過將尺寸常數整合至主題中,此套件簡化了佈局調整,無需依賴外部設定或硬編碼值。此方法提升可維護性與可擴展性,特別適用於具有複雜佈局的大型應用。該套件支援所有主要平台,確保跨平台一致性。

適用情境

  • 響應式佈局管理
  • 集中式維度配置
  • 跨平台 UI 一致性
  • 主題驅動的間距和尺寸
  • 簡化使用者介面縮放
  • 保持設計系統完整性

主要特色

  • 將維度整合到 ThemeData 中
  • 支援平台無關的尺寸
  • 啟用基於主題的動態維度
  • 減少對硬編碼值的依賴
  • 促進設計系統對齊
  • 與現有主題無縫配合

適合對象

  • 大規模 Flutter 應用
  • 設計系統實施
  • 跨平台開發
  • 注重UI一致性的團隊
  • 使用主題化樣式的開發者

使用建議

  • 需要理解 Flutter 主題系統
  • 可能需要為自定義維度邏輯進行額外設定
  • 限制為基於主題的維度處理
  • 不是完整的佈局框架
  • 最好與響應式佈局策略搭配使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

📏 dimensions_theme

dimensions_theme provides a theme extension to easily define and access app dimensions such as blank spaces, padding, border radius, and other dimensions within the Flutter theme.

Define your dimensions

// Uses tokens that best fit your project needs. You can also use multiple enums
enum Dimension {
  xlarge,
  large,
  medium,
  small,
  xsmall,
}

...

MaterialApp(
  theme: ThemeData(
    extensions: const [
      DimensionsTheme({
        Dimension.xlarge: 20,
        Dimension.large: 16,
        Dimension.medium: 12,
        Dimension.small: 8,
        Dimension.xsmall: 4,
      }),
    ],
  ),
);
Uses multiple enum for dimensions

The Dimensions theme extension supports using multiple enums as dimension tokens. This can be useful if you want to give different kinds of dimensions value their own enum.

enum Space {
  xlarge,
  large,
  medium,
  small,
  xsmall,
}

enum Padding {
  xlarge,
  large,
  medium,
  small,
  xsmall,

  screen,
}

...

MaterialApp(
  theme: ThemeData(
    extensions: const [
      DimensionsTheme({
        Space.xlarge: 20,
        Space.large: 16,
        Space.medium: 12,
        Space.small: 8,
        Space.xsmall: 4,

        Padding.xlarge: 20,
        Padding.large: 16,
        Padding.medium: 12,
        Padding.small: 8,
        Padding.xsmall: 4,
        Padding.screen: 20,
      }),
    ],
  ),
);

Consume dimensions values

You can access any dimension value using the get:

Dimensions.of(context).get(Dimension.small);

Additionally, this package provides helpers to make it easier to work with defined dimensions.

Padding

The padding context extension constructs EdgeInsets using the values defined in the dimensions theme for a given dimension token.

Padding(
  padding: context.padding.all(Dimension.small)
  child: ...
)

This extension provides counterparts to all EdgeInsets constructors but uses Dimension tokens instead of raw double values.

context.padding.all(Dimension.small)

context.padding.symmetric(
  horizontal: Dimension.medium,
  vertical: Dimensions.small,
)

context.padding.only(
  left: Dimension.large
  top: Dimension.large,
)
Blank spaces

The Space widget creates a SizedBox with the values defined in the dimensions theme for a given dimension token.

Column(
  children: [
    SomeWidget(),
    Space(Dimensions.small),
    SomeWidget(),
  ]
)

Alternatively, you can use the SpaceDimensionsMixin to construct Space widgets directly from your tokens:

/// Add `SpaceDimensionsMixin` to your dimension token responsible for spaces
enum Spaces with SpaceDimensionsMixin {
  large,
  medium
  small,
}

...

Column(
  children: [
    SomeWidget(),
    Spaces.small(),
    SomeWidget(),
  ]
)

All space widgets come with .w and .h constructors to restrict the blank space in one axis, respectively width and height.

Space.h(Dimensions.small)
Space.w(Dimensions.small)

Spaces.small.h()
Spaces.small.w()
Border radius

The radius context extension constructs Radius using the values defined in the dimensions theme for a given dimension token.

Container(
  decoration: BoxDecoration(
    borderRadius: BorderRadius.all(
      context.radius.circular(Dimensions.large),
    ),
  ),
)

This extension provides counterparts to all Radius constructors but uses Dimension tokens instead of raw double values.

context.radius.elliptical(Dimensions.large);
context.radius.circular(Dimensions.small, Dimensions.large);

The extension also provides a counterpart to BorderRadius.circular().

Container(
  decoration: BoxDecoration(
    borderRadius: borderRadius.circular(Dimensions.large),
  ),
)

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。