ext_kit 1.0.0 copy "ext_kit: ^1.0.0" to clipboard
ext_kit: ^1.0.0 copied to clipboard

A comprehensive Flutter/Dart package providing powerful extensions for String, DateTime, int, double, num, List, Iterable, Map, Widget, BuildContext, Color, Duration, and dynamic types. Boost your pro [...]

Ext Kit #

pub package License: MIT

A comprehensive Flutter/Dart package providing 100+ powerful extensions for common data types. Boost your productivity with utility methods you use every day.

Features #

Type Extensions
String Validation (email, URL, phone, IP, etc.), capitalize, camelCase, snakeCase, truncate, mask, slug, reversed, wordCount
DateTime Add/subtract time, isBetween, timeAgo, copyWith, isToday, isWeekend, daysInMonth, quarter
int isPrime, factorial, fibonacci, duration creation (.seconds, .hours), isMultipleOf
double toPrecision, duration creation, toPositive/toNegative
num toCurrency, toCompact, toFileSize, isBetween, clampMin/clampMax, delay
List sum, average, product, rotated, reversedList, distinctBy, operations (+, -, *)
Iterable groupBy, distinctBy, chunk, minBy/maxBy, flatten, takeLastWhile
Map getOrNull, getOrDefault, whereKeys, whereValues, mapKeys, mapValues, merge, inverted
Widget paddingAll, marginAll, center, expanded, flexible, visible, opacity, onTap, clipRRect, safeArea, hero
BuildContext width/height, isDarkMode, isPhone/isTablet/isDesktop, responsiveValue, navigation, showSnackBar, hideKeyboard
Color toHex, fromHex, darken/lighten, darkenBy/lightenBy, isDark/isLight, opacity presets
Duration timeToString, delay, remainingHours/Minutes/Seconds
dynamic Type checks (isInt, isString, etc.), isNull/isNotNull, printError/printInfo

Installation #

Add to your pubspec.yaml:

dependencies:
  ext_kit: ^1.0.0

Then run:

flutter pub get

Usage #

Import the package:

import 'package:ext_kit/ext_kit.dart';

String Extensions #

// Validation
'test@email.com'.isEmail;      // true
'192.168.1.1'.isIPv4;          // true
'+6281234567890'.isPhoneNumber; // true

// Transformation
'hello world'.capitalize;       // 'Hello World'
'hello world'.camelCase;        // 'helloWorld'
'Hello World'.snakeCase;        // 'hello_world'
'Hello World'.toSlug();         // 'hello-world'
'hello'.reversed;               // 'olleh'
'Hello World Example'.truncate(10); // 'Hello W...'
'1234567890'.mask();            // '******7890'
'hello world'.wordCount;        // 2

DateTime Extensions #

final now = DateTime.now();
now.isToday();            // true
now.isWeekend();          // depends on the day
now.addDays(5);           // 5 days from now
now.startOfMonth;         // 1st of this month at 00:00
now.daysInMonth;          // 28, 29, 30, or 31
now.quarter;              // 1-4
now.timeAgo();            // 'just now', '5 minutes ago', etc.

now.isBetween(
  now.subtractDays(1),
  now.addDays(1),
);  // true

now.copyWith(month: 6);  // same date but in June

int Extensions #

7.isPrime;           // true
5.factorial;         // 120
8.isFibonacci;       // true
10.isMultipleOf(5);  // true
7.nextPrime;         // 11

// Duration creation
2.seconds;    // Duration(seconds: 2)
500.ms;       // Duration(milliseconds: 500)

num Extensions #

1500.0.toCurrency();              // '$1,500.00'
1500.0.toCurrency(symbol: '€');   // '€1,500.00'
1234567.toCompact();              // '1.2M'
1048576.toFileSize();             // '1.0 MB'
50.isBetween(1, 100);             // true
await 2.delay();                  // waits 2 seconds

List & Iterable Extensions #

[1, 2, 3, 4, 5].sum;              // 15
[1, 2, 3, 4, 5].average;          // 3.0
[1, 2, 3, 4, 5].product;          // 120
[1, 2, 3, 4, 5].rotated(2);       // [3, 4, 5, 1, 2]
[1, 2, 2, 3].distinct().toList();  // [1, 2, 3]
[1, 2, 3] + [4, 5];               // [1, 2, 3, 4, 5]
[1, 2, 3] * 2;                    // [1, 2, 3, 1, 2, 3]

// Group by
['apple', 'avocado', 'banana'].groupBy((s) => s[0]);
// {a: [apple, avocado], b: [banana]}

// Chunk
[1, 2, 3, 4, 5].chunk(2).toList(); // [[1, 2], [3, 4], [5]]

Map Extensions #

final map = {'a': 1, 'b': 2, 'c': 3};
map.getOrDefault('d', 0);              // 0
map.getOrNull('d');                    // null
map.whereValues((v) => v > 1);        // {b: 2, c: 3}
map.whereKeys((k) => k != 'a');       // {b: 2, c: 3}
map.mapKeys((k) => k.toUpperCase());  // {A: 1, B: 2, C: 3}
map.merge({'d': 4});                  // {a: 1, b: 2, c: 3, d: 4}
map.inverted;                         // {1: a, 2: b, 3: c}

Widget Extensions #

// Padding & Margin
Text('Hello').paddingAll(16.0);
Text('Hello').paddingSymmetric(horizontal: 8.0);
Text('Hello').marginAll(16.0);

// Layout
Text('Centered').center();
Text('Expanded').expanded();
Text('Flexible').flexible();

// Transform
Image.network(url).clipRRect(radius: 12.0);
Text('Hero').hero('my-tag');
Text('Conditional').visible(showText);
Text('Tappable').onTap(() => print('tapped'));
Text('Safe').safeArea();

BuildContext Extensions #

// Screen info
context.width;         // screen width
context.height;        // screen height
context.isPhone;       // is phone form factor
context.isTablet;      // is tablet form factor
context.isDarkMode;    // is dark mode

// Theme access
context.textTheme;     // TextTheme
context.colorScheme;   // ColorScheme
context.platform;      // TargetPlatform
context.isIOS;         // is iOS platform
context.isAndroid;     // is Android platform

// Navigation
context.to(MyPage());
context.to(MyPage(), navigateType: NavigateType.replace);
context.to('/route-name');
context.back();

// Responsive values
context.responsiveValue(
  mobile: 14.0,
  tablet: 18.0,
  desktop: 22.0,
);

// Utilities
context.showSnackBar('Success!');
context.hideKeyboard();

Color Extensions #

Colors.red.toHex();           // '#ffff0000'
ColorExt.fromHex('#FF5733');  // Color

Colors.red.darken;            // darker shade
Colors.red.lighten;           // lighter shade
Colors.red.darkenBy(0.2);     // 20% darker
Colors.red.isDark;            // true/false

Colors.red.opacityMedium;    // 50% opacity

Duration Extensions #

Duration(hours: 1, minutes: 30, seconds: 45).timeToString; // '01:30:45'
Duration(seconds: 90).timeToStringWithMs; // '00:01:30.000'
await Duration(seconds: 2).delay();

Dynamic Extensions #

dynamic value = 10;
value.isInt;       // true
value.isNull;      // false
value.isNotNull;   // true
value.printInfo();  // logs info

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
150
points
27
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter/Dart package providing powerful extensions for String, DateTime, int, double, num, List, Iterable, Map, Widget, BuildContext, Color, Duration, and dynamic types. Boost your productivity with 100+ utility methods.

Repository (GitHub)
View/report issues

Topics

#extensions #utils #utilities #helper #dart

License

MIT (license)

Dependencies

flutter

More

Packages that depend on ext_kit