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 Text widget: "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.