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

spaces 封面
套件詳情v0.5.0

spaces

定義全域間距常數,以建立一致且響應式應用程式。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
31
喜歡數
18
Pub 分數
130

安裝套件

flutter pub add spaces

套件介紹

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

spaces 套件提供全域定義的間距常數,以確保在 Flutter 應用程式中實現一致且響應式的間距。透過提供預先定義、可擴展的邊距、內邊距和間隙值,它簡化了在不同螢幕尺寸和平台上的 UI 開發。此套件專為響應式佈局設計,讓開發者能在不硬編碼數值的情況下維持視覺和諧。它支援所有主要的 Flutter 平台,非常適合需要統一間距行為的跨平台專案。

適用情境

  • 構建響應式佈局
  • 保持一致的UI間距
  • 跨平台應用程式開發
  • 簡化邊距和內邊距管理
  • 建立可擴展的設計系統

主要特色

  • 預定義的間距常數
  • 響應式間距支援
  • 平台無關的設計
  • 透過 pub 輕鬆整合
  • 乾淨、可重複使用的間距值

適合對象

  • 設計系統實施
  • 跨平台 Flutter 應用
  • 注重使用者介面一致性的團隊
  • 開發人員優先考慮可維護性
  • 需要可擴展間距的專案

使用建議

  • 需要遵循預定義的間距比例
  • 間距值的自訂有限
  • 最適合使用一致設計語言的專案
  • 不適用於高度動態或變更間距的需求
  • 依賴於主題或應用結構中的正確設定

原始 README

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

logo

Spaces

Defining global spacing constants for building consistent and responsive apps.

Install

Add the dependency to your pubspec.yaml :

dependencies:
    spaces: <version>

Quick start

return MaterialApp(
    // Defining
    builder: (context, child) => Spacing(
        dataBuilder: (context) {
          final mediaQuery = MediaQuery.of(context);
          if (mediaQuery.size.width > 500) {
            return SpacingData.generate(30);
          }
          return SpacingData.generate(10);
        },
        child: child,
    ),
    home:Builder(builder: (context) {
        // Using
        final spacing = Spacing.of(context);
        return SpacedColumn.normal(
            padding: spacing.insets.all.semiBig,
            children: <Widget>[
                Text('hello'),
                Space.big(),
                Text('world'),
            ],
        );
      })
    ),
)

Usage

Configuring spacing

A Spacing widget should declare a global spacing configuration for your application.

return MaterialApp(
    builder: (context, child) => Spacing.fixed(
        data: SpacingData.generate(10.0), // This generates a set of spacing constants for your apps, from a base space of `10.0`.
        child: child,
    ),
    /// ...
)
Generate

By calling the Spacing.generate constructor, a set of constants are automatically generated from a single base value.

The generated values are :

  • extraSmall : value * 0.2
  • small : value * 0.4
  • semiSmall : value * 0.6
  • normal : value
  • semiBig : value * 1.5
  • big : value * 2.5
  • extraBig : value * 5.0
SpacingData.generate(10.0)
From spaces

If you want to define the various spacing values, you can use the

SpacingData.fromSpaces(
    extraSmall: 1.0,
    small: 2.0,
    semiSmall: 4.0,
    normal: 8.0,
    semiBig: 12.0,
    big: 20.0,
    extraBig: 100.0,
)

Responsive spacing

You can define the dataBuilder property of the Spacing constructor to generate a configuration from the given context.

Spacing(
    dataBuilder: (context) {
        final mediaQuery = MediaQuery.of(context);
        return SpacingData.generate(mediaQuery.size.width > 300.0 ? 20.0 : 10.0),
    },
    child: child,
)

Using constants

To access various spacing constants, simply use the Spacing.of(context) getter, or the context.spacing() extension method.

final spacing = Spacing.of(context);
// spacing.spaces.semiBig
Size variants

There are seven availables spacing constants : extraSmall, small, semiSmall, normal, semiBig, big, extraBig;

final spacing = Spacing.of(context);
return SizedBox(
    width: spacing.spaces.semiSmall,
);
Insets helpers

You have EdgeInsets presets available from <spacing>.insets.<selector>.<size>.

The available selectors are : all, horizontal, vertical, onlyLeft, onlyTop, onlyRight, onlyBottom, exceptLeft, exceptRight, exceptTop, exceptBottom.

final spacing = Spacing.of(context);
return Padding(
    padding: spacing.insets.exceptLeft.semiBig,
    child: Text('Hello'),
);

Widgets

Space

The Space widget uses gap under the hood to define a space in a Flex, Column, Row or Scrollable (such as ListView).

return Column(
    children: [
        Text('hello'),
        const Space.semiSmall(),
        Text('world'),
    ],
);
SpacedFlex / SpacedColumn / SpacedRow

Like Flex / Column / Row, but with additional padding and spaceBetween properties.

final spacing = Spacing.of(context);
return SpacedColumn.small(
    padding: spacing.insets.all.normal,
    children: [
        Text('hello'),
        Text('world'),
    ],
);

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。