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

套件詳情v3.1.0

gap

用於在 Column 和 Row 等 Flex 小部件或捲動檢視中輕鬆加入間距的 Flutter 小部件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
47.3萬
喜歡數
1020
Pub 分數
160

安裝套件

flutter pub add gap

套件介紹

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

gap 套件提供簡單的 Flutter 小工具,可輕鬆在 Flex 容器(如 Columns、Rows 和滾動視圖)內加入一致的間距。它消除了手動使用 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.

所屬分類

原始碼儲存庫

使用此套件的專案

所在榜單