Universal Extensions for Flutter
A lightweight, powerful Flutter package providing universal extension methods for Widgets, Strings, Numbers, BuildContext, and more. Designed to reduce boilerplate and make UI development clean, readable, and fast.
โจ Features
๐งฉ Widget Extensions
- Add padding:
.padAll(),.padSymmetric(),.padOnly() - Add margin:
.marginAll(),.marginSymmetric() - Alignment helpers:
.center(),.align() - Tap handler:
.onTap() - Layout helpers:
.sized(),.expanded(),.flexible() - SafeArea wrapper:
.safeAre()
๐ค String Extensions
- Convert directly to
Textwidget:"Hello".txt() capitalize()- Safe parsing:
toInt(),toDouble() - Email Validation Regex:
isEmail()
๐ข Num Extensions
- Quick space widgets:
10.w,20.h - EdgeInsets:
10.all,10.horizontal,10.vertical
๐งญ BuildContext Extensions
- Size:
context.width,context.height - Themes:
context.theme,context.textTheme - Safe pop:
context.safePop()
DateTime Extensions
- Check if its today:
isToday()
๐ Installation
Add the package to your pubspec.yaml:
dependencies:
universal_extensions: ^1.0.0
Then import it:
import 'package:universal_extensions/universal_extensions.dart';
๐ Usage Examples
Padding & Margin
Text("Hello World")
.padAll(16)
.marginSymmetric(horizontal: 20);
Centering a widget
Icon(Icons.star).center();
Making any widget clickable
Container(width: 100, height: 50)
.onTap(() => print("Tapped!"));
String to Text Widget
"Welcome".txt(style: context.textTheme.titleLarge);
Number spacing helpers
Column(
children: [
20.h,
Text("Item 1"),
10.h,
Text("Item 2"),
],
);
BuildContext utilities
SizedBox(
width: context.width * 0.5,
height: context.height * 0.2,
);
๐ Why Use Universal Extensions?
- Cleaner widget trees
- Less nesting (Padding โ Container โ GestureDetector โ SizedBox)
- Faster UI development
- Reusable, consistent code across projects
- Minimal, dependency-free
๐งช Example Project
See the /example folder for a full Flutter demo.
๐ค Contributing
Pull requests are welcome! If you want to add more extensions (animations, colors, lists, dates, async helpers), feel free to open an issue.
๐ License
This package is open-source and available under the MIT License.