gapx 0.0.1 copy "gapx: ^0.0.1" to clipboard
gapx: ^0.0.1 copied to clipboard

A smart, ScreenUtil-aware spacing widget for Flutter that replaces SizedBox and automatically adapts to Row, Column, and Flex layouts.

Gapx #

A smart, ScreenUtil-aware spacing widget for Flutter that replaces SizedBox and automatically adapts to Row, Column, Flex, and sliver layouts.


✨ Why Gapx? #

In Flutter, spacing is usually handled with SizedBox(height: x) or SizedBox(width: x). This becomes repetitive and error‑prone, especially in responsive apps using flutter_screenutil.

Gapx solves this by:

  • Automatically detecting layout direction (Row / Column / Flex)
  • Applying height for vertical layouts and width for horizontal layouts
  • Seamlessly scaling values using flutter_screenutil
  • Eliminating the need to use .h or .w
  • Supporting slivers out of the box

πŸš€ Features #

  • βœ… Drop‑in replacement for SizedBox
  • βœ… Auto adapts to Row, Column, and Flex
  • βœ… ScreenUtil synced (no .h / .w required)
  • βœ… Optional background color (useful for debugging)
  • βœ… Sliver support (SliverGapx)
  • βœ… Lightweight & performant (RenderObject based)

πŸ“¦ Installation #

Add this to your pubspec.yaml:

dependencies:
  gapx: ^0.0.1

Then run:

flutter pub get

⚠️ Required Setup #

Gapx relies on flutter_screenutil for responsive scaling.

Make sure you initialize ScreenUtil at the root of your app:

ScreenUtilInit(
  designSize: const Size(360, 690),
  builder: (_, child) => MaterialApp(
    home: child,
  ),
  child: const MyHomePage(),
);

⚠️ If ScreenUtilInit is not used, spacing will not scale as expected.


🧩 Basic Usage #

Column (Vertical spacing) #

Column(
  children: const [
    Text('Above'),
    Gapx(20), // height: 20.h
    Text('Below'),
  ],
);

Row (Horizontal spacing) #

Row(
  children: const [
    Icon(Icons.star),
    Gapx(12), // width: 12.w
    Text('Star'),
  ],
);

No need to think about height or width β€” Gapx handles it automatically.


🎨 With Color (Debugging / Layout Help) #

Gapx(
  16,
  color: Colors.redAccent,
);

πŸ“ Expanded Gap #

Use Gapx.expand when you want the gap to take maximum space in the cross axis:

Gapx.expand(24);

🧱 Flexible Gap #

Use MaxGap inside flexible layouts:

Row(
  children: const [
    Text('Left'),
    MaxGap(20),
    Text('Right'),
  ],
);

πŸ“œ Sliver Support #

Gapx also works inside slivers:

CustomScrollView(
  slivers: const [
    SliverToBoxAdapter(child: Text('Top')),
    SliverGapx(24),
    SliverToBoxAdapter(child: Text('Bottom')),
  ],
);

🧠 How It Works #

  • Detects parent RenderFlex direction
  • Maps spacing to main axis automatically
  • Applies ScreenUtil scaling internally
  • Uses a custom RenderBox for performance

πŸ†š Comparison #

Approach Responsive Direction Aware Boilerplate
SizedBox ❌ ❌ High
Gap ❌ βœ… Medium
Gapx βœ… βœ… Low

πŸ› οΈ Roadmap #

  • ❌ Optional fallback when ScreenUtil is not initialized
  • ❌ Animation support
  • ❌ Axis‑specific constructors
  • ❌ Widget tests

🀝 Contributing #

Contributions are welcome!

  1. Fork the repo
  2. Create your feature branch
  3. Commit changes
  4. Open a pull request

πŸ“„ License #

MIT License


⭐ Support #

If you find this package useful, please ⭐ star the repo and share feedback.

Happy Fluttering πŸš€

1
likes
160
points
127
downloads

Publisher

unverified uploader

Weekly Downloads

A smart, ScreenUtil-aware spacing widget for Flutter that replaces SizedBox and automatically adapts to Row, Column, and Flex layouts.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_screenutil

More

Packages that depend on gapx