Search packages, repositories and app categories

Package detailsv3.1.0

gap

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

AndroidiOSWebmacOSWindowsLinux
30-day downloads
473K
Likes
1K
Pub points
160

Install package

flutter pub add gap

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The gap package provides simple Flutter widgets to easily add consistent spacing within Flex containers like Columns, Rows, and scrolling views. It eliminates the need for manual EdgeInsets or SizedBox by offering a clean, declarative way to insert gaps between children. Ideal for improving layout readability and reducing boilerplate code in UIs with nested layouts. The package supports all major platforms and integrates seamlessly with existing Flutter projects.

Use cases

  • Adding uniform spacing in Column and Row layouts
  • Simplifying spacing in scrollable lists
  • Improving UI consistency across different screen sizes
  • Reducing boilerplate in complex nested layouts
  • Creating responsive designs with minimal code
  • Enhancing developer productivity in UI development

Key features

  • Minimal API with intuitive syntax
  • Supports all Flutter platforms
  • Automatic handling of spacing in scrollable views
  • No need for SizedBox or EdgeInsets in common cases
  • Composable with other layout widgets
  • Lightweight and dependency-free

Suitable for

  • Developers seeking cleaner layout code
  • Projects with frequent use of Columns and Rows
  • UI-heavy applications requiring consistent spacing
  • Teams prioritizing maintainable and readable code
  • Flutter beginners learning layout patterns
  • Apps targeting multiple platforms with uniform spacing

Considerations

  • Not necessary for simple layouts without spacing
  • May introduce slight overhead in very large lists
  • Best used alongside other layout optimization practices
  • Does not replace advanced spacing solutions like custom render objects
  • Limited to spacing within Flex containers
  • Requires understanding of Flutter's layout system

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package

Rankings