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

插件详情v3.1.0

gap

用于在 Column 和 Row 等 Flex 小部件或滚动视图中轻松添加间距的 Flutter 小部件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
47.3万
喜欢数
1020
Pub 分数
160

安装插件

flutter pub add gap

插件介绍

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

gap 包提供简单的 Flutter 小部件,可轻松在 Column、Row 和滚动视图等 Flex 容器中添加一致的间距。它消除了手动使用 EdgeInsets 或 SizedBox 的需求,通过一种简洁、声明式的方法在子组件之间插入间距。非常适合提升嵌套布局的布局可读性,并减少 UI 中的样板代码。该包支持所有主要平台,并可无缝集成到现有的 Flutter 项目中。

适合场景

  • 在 Column 和 Row 布局中添加统一的间距
  • 简化可滚动列表中的间距
  • 改善不同屏幕尺寸之间的UI一致性
  • 减少复杂嵌套布局中的样板代码
  • 使用最少的代码创建响应式设计
  • 提升UI开发中的开发者生产力

主要特点

  • 简洁的 API,语法直观
  • 支持所有 Flutter 平台
  • 滚动视图中自动处理间距
  • 在常见情况下无需使用 SizedBox 或 EdgeInsets
  • 可与其他布局小部件组合使用
  • 轻量且无依赖

适合对象

  • 寻求更简洁布局代码的开发者
  • 频繁使用列和行的项目
  • 需要一致间距的UI密集型应用程序
  • 优先考虑可维护性和可读性代码的团队
  • Flutter 初学者学习布局模式
  • 针对多个平台且间距统一的应用程序

使用建议

  • 对于没有间距的简单布局来说并非必要
  • 在非常大的列表中可能会引入轻微开销
  • 最好与其他布局优化实践配合使用
  • 不会替代像自定义渲染对象之类的高级间距解决方案
  • 限于Flex容器内的间距
  • 需要了解 Flutter 的布局系统

原始 README

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

Gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views.

Pub

Introduction

When it comes to add empty space between widgets inside a Column or a Row, we have multiple options:

  • We can either add a Padding around these widgets but it's very verbose
  • Or we can add SizedBox widgets between them.

Gap is another option. It's like SizedBox but you don't have to know if it's inside a Row or a Column. So that it's less verbose than using a SizedBox.

Getting started

In your library add the following import:

import 'package:gap/gap.dart';

Then you just have to add a Gap inside a Column or a Row with the specified extent.

return Column(
  children: <Widget>[
    Container(color: Colors.red, height: 20),
    const Gap(20), // Adds an empty space of 20 pixels.
    Container(color: Colors.red, height: 20),
  ],
);

The Gap widget also works inside Scrollable widgets such as ListViews. In these cases, it will occupy the space in the same direction as the Scrollable.

MaxGap

This package also comes with a MaxGap widget. The MaxGap widget will try to fill the available space in a Column or a Row with the specified size. If the available space is lesser than the specified size, the MaxGap widget will only take the available space.

It's useful when you want to have a gap that shrinks to avoid an overflow otherwise.

Other parameters

By default a Gap will have no extent in the opposite direction of the Flex parent. If you want the Gap to have a color, you'll have to set the color and the crossAxisExtent parameters. You can also use the Gap.expand constructor to expand the Gap in the opposite direction of the Flex parent.

SliverGap

There is also a Sliver version of the Gap widget:

return CustomScrollView(
  slivers: <Widget>[
    const SliverGap(20), // Adds an empty space of 20 pixels.
  ],
);

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

源码仓库

使用此插件的项目

所在榜单