搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。