搜索插件、代码仓与 APP 分类

插件详情v2.2.0

flutter_gutter

让您的用户界面摆脱混乱!确保所有组件之间的视觉间距一致,适应轴向方向,并能响应屏幕尺寸。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3120
喜欢数
65
Pub 分数
150

安装插件

flutter pub add flutter_gutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flutter Gutter 是一个响应式 UI 工具包,可确保在不同屏幕尺寸和轴向方向上,小部件之间的间距保持一致。它通过根据方向(水平或垂直)和设备尺寸自动调整内边距和外边距,简化了布局管理,帮助开发者无需手动计算即可保持界面整洁、对齐。非常适合创建流畅、可扩展的设计,在任何平台上都显得专业。

适合场景

  • 使用一致的间距创建响应式布局
  • 跨方向自动调整填充/边距
  • 为多平台应用构建可适应的用户界面
  • 在动态小部件布局中保持视觉和谐
  • 使用最少的代码简化复杂的布局逻辑
  • 通过统一的间距确保可访问性

主要特点

  • 自动轴感知间距
  • 对屏幕尺寸变化做出响应
  • 支持所有主要平台
  • 所需的最小样板代码
  • 用于水平和垂直间距的直观 API
  • 与现有 Flutter 小部件无缝集成

适合对象

  • 专注于响应式设计的开发人员
  • 构建跨平台应用程序的团队
  • UI/UX 设计师实现一致的间距
  • 需要自适应布局的项目
  • 初学者学习Flutter布局原则
  • 针对各种屏幕尺寸的应用

使用建议

  • 可能需要调整以满足高度自定义的间距需求
  • 仅限与间距相关的功能
  • 不适用于非布局用例
  • 取决于对Flutter布局系统的正确使用
  • 最佳搭配其他布局工具以实现复杂设计
  • 不替代完整的布局框架,如 Flex 或 Grid

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Gutter

Pub Version GitHub Workflow Status

Ensure all visual gaps between your widgets are consistent, adapted to the axis direction, and respond to screen size!

Core Features

Provides a Gutter and Margin that correspond to Material Design's Responsive Layout system.

Gutters and margins:

  1. Create a vertical gap in vertical layouts (Column, vertical Scrollable, etc) and a horizontal gap in horizontal layouts (Row, horizontal Scrollable, etc).
  2. Size the gap according to the current screen size and Material Design's corresponding breakpoint definition (small gap on small screens, larger gap on large screens)

GutterTiny, GutterSmall, GutterLarge and GutterExtraLarge all provide gaps that are factors of the base gutter size for situations where larger or smaller gaps are more appropriate. By default, each successive gutter size is a factor of 2 larger than the previous. For convenience, alternative constructors are provided (Gutter.tiny, etc.) for each gutter size.

For more flexibility, you can also use the provided extension on BuildContext to reference the gutter and margin sizes directly (context.gutter, context.gutterLarge, context.margin, etc).

Use Gap to create an axis aligned spacing with an explicit size.

Supported Widgets

Flutter Gutter's widgets traverse up the widget tree until they find an ancestor that meets one of the following conditions:

  1. GutterConfiguration.maybeOf(context).customWidgetToAxis(widget) returns a non-null Axis (this is a custom function that lets you extend Flutter Gutter to support arbitrary widgets).
  2. widget is a scrollable with a defined axis.
  3. widget has an Axis direction attribute (for example, Flutter Gutter supports Boxy's widgets automatically).

Note that case 3 means that ANY widget with an axis is supported, however this is a dynamic check which means that the Dart compiler will not be able to tree shake out any axis attributes on any widget. This may increase your app's bundle size by a very small amount.

I have a Github issue against Flutter to add an explicit axis scope to Flutter which would resolve this limitation. If you like using Flutter Gutter and want to see it improved, please upvote the linked issue.

Example

Without flutter_gutter you have to manually specify the axis direction (by using height or width) and specify size of the gap yourself:

return Column(
  children: [
    const Text('I hate using sized box.'),
    SizedBox(height: 10),
    const Text('If only there were a better way...'),
  ],
);

With flutter_gutter the Gutter widget identifies that it's in a vertical layout (Column) and automatically creates a vertical gap. It also looks up the screen size and sizes the gap accordingly so you don't have to specify a gap size manually:

return Column(
  children: [
    const Text('I hate using sized box.'),
    Gutter(),
    const Text('And now I don\'t have to!'),
  ],
);

To use the gutter sizes directly, use the extension on context:

return Padding(
  padding: EdgeInsets.only(left: context.gutter, right: context.gutterSmall),
  child: Text('This is the margin size on this device: ${context.margin}'),
);

To use Gutter with custom widgets that don't expose an axis argument or to override the default gutter spacing or scaling, use GutterConfiguration:

return GutterConfiguration(
  data: GutterConfigurationData(
    widgetToAxis: (widget) {
      if (widget is MyCustomColumn) {
        return Axis.vertical;
      }
      return null;
    },
  ),
  child: MyCustomColumn(
    children: [
      const Text('This widget isn\'t supported by `Gutter` ).'),
      Gutter(),
      const Text('But with `GutterConfiguration` I can make Gutter work with any widget!'),
    ],
  ),
);

Why not just use the existing Gap package?

Gap and Flutter Gutter are very similar, but Flutter Gutter does a few extra things Gap does not:

  1. Auto sizes gap spacing according to the Material breakpoints system (see "Core Features" above).
  2. Detects the axis of ANY widget that exposes an Axis direction attribute or getter (see "Supported Widgets" above).
  3. Allows you to add support for arbitrary widgets using GutterConfiguration and widgetToAxis.

Personally, I especially appreciate feature 1 as it makes it easier for me to add spacing and ensures that spacing and padding in different parts of my app are consistently sized. However, if none of the above features are important to you, you'll likely prefer the Gap package!

所属分类

依赖

依赖清单 1 项

  • flutter_adaptive_scaffold>=0.3.0 <1.0.0

源码仓库

使用此插件的项目