Effortless Dart Coding with dart_extensions_pro

Introduction

Introducing dart_extensions_pro a Dart package offering a rich collection of handy extensions and helper functions designed to enhance your development workflow. By simplifying common tasks and providing streamlined solutions, it lets developers write code more efficiently and focus on building features rather than repetitive boilerplate.

Key Features

  • ๐Ÿ“Š Comparison : Simplify comparison operations with intuitive extension methods.
  • ๐Ÿ“… Date Handling : Effortlessly manage date and time with a variety of helpful functions.
  • โœ๏ธ String Utilities : Enhance string manipulation with powerful utility functions.
  • ๐Ÿ“‹ List Enhancements : Improve list handling with convenient extensions for common operations.
  • ๐Ÿงญ Navigation : Streamline navigation tasks with specialized navigation functions.
  • ๐Ÿ‘† Tap Gestures : Easily handle tap gestures to improve user interaction.
  • ๐Ÿ” Iterable Enhancements : Optimize iterable processing with enhanced methods.
  • ๐ŸŽจ Color Conversion : Simplify color manipulations and conversions with dedicated functions.
  • ๐Ÿ”ข Number Utilities : Access a range of number-related utilities for calculations and formatting.
  • ๐Ÿ› ๏ธ Utility Functions : Utilize various handy utility functions to simplify your coding experience.

Installation

Add the dependency to your pubspec.yaml file and run pub get:

dependencies:
  dart_extensions_pro: ^0.0.1

Then import the package into your Dart file:

import 'package:dart_extensions_pro/dart_extensions_pro.dart';

Analytics

Visit EXTENSIONS.md for a complete list of all available extensions.

Extensions:                    271
Helper Classes:                7
Helper Functions & Getters:    21
Typedefs:                      7
Mixins:                        2

Quick Preview

String Extension

'hello'.iscapitalize();           // Hello
'Copy this text'.copyTo();        // Copies string to clipboard
'test@example.com'.isValidEmail(); // true
'flutter'.reverse();              // rettulf
'madam'.isPalindrome();           // true
'flutter example'.toCamelCase(); // FlutterExample
'{"name": "Flutter"}'.decodeJson(); // {name: Flutter}

Comparison Extension

5.gt(3);  // true โ€” 5 is greater than 3
3.lt(5);  // true โ€” 3 is less than 5
5.eq(5);  // true โ€” 5 is equal to 5
3.lte(3); // true โ€” 3 is less than or equal to 3
5.gte(3); // true โ€” 5 is greater than or equal to 3
5.ne(3);  // true โ€” 5 is not equal to 3

Date Extension

DateTime.now().isSameDate(DateTime(2023, 9, 14)); // true/false
DateTime.now().isToday();       // true
DateTime.now().isTomorrow();    // false
DateTime.now().wasYesterday();  // false
DateTime.now().addDays(5);      // adds 5 days
DateTime.now().addMonths(3);    // adds 3 months
DateTime.now().addYears(2);     // adds 2 years
DateTime.now().subtractDays(7); // subtracts 7 days
DateTime.now().subtractMonths(1); // subtracts 1 month
DateTime.now().subtractYears(1);  // subtracts 1 year

List Extension

final list = [1, 2, 3] << 4;                          // [1, 2, 3, 4]
list.replaceFirstWhere(10, (item) => item == 2);  // replaces first 2 with 10
list.replaceLastWhere(20, (item) => item > 1);    // replaces last item > 1 with 20

Navigation Extension

context.to(MyPage());
context.toNamed('/home');
context.back();
context.backUntil((route) => route.isFirst);
context.toWithReplace(AnotherPage());
context.replaceWithNamed('/dashboard');
context.toAndRemoveAll(HomePage(), (route) => false);
context.toNamedAndRemoveAll('/login', (route) => false);

Gesture Extension

widget.onInkTap(() => 'Tapped!'.logMsg());
widget.onTap(() => 'Tapped!'.logMsg());
widget.onDoubleTap(() => 'Double Tapped!'.logMsg());
widget.onTapCancel(() => 'Tap Cancelled!'.logMsg());
widget.onLongPress(() => 'Long Pressed!'.logMsg());
widget.onTapDown((details) => 'Tap Down!'.logMsg());
widget.onScale(
  onScaleStart: (details) => 'Scale Started!'.logMsg(),
  onScaleUpdate: (details) => 'Scaling!'.logMsg(),
  onScaleEnd: (details) => 'Scale Ended!'.logMsg(),
);

Iterable Extension

iterable.lastElementIndex;
iterable.hasSingleElement;
iterable.addAllMatchingTo(targetList, (e) => e.isEven);
iterable.whereFilter((e) => e.isEven);
iterable.whereFilterIndexed((index, e) => index % 2 == 0);
iterable.mapTransform((e) => e.toString());
iterable.skipElements(2);
iterable.takeLastElements(2);
iterable.skipWhileElements((e) => e < 5);
iterable.skipLastElements(2);

Color Conversion

String.toColor();                        // hex string โ†’ Color object
HexColor.getColorFromHex(hexColor);     // hex string โ†’ integer color value
HexColor(hexColor);                      // creates a HexColor instance

Number Utilities

num.negative;                          // converts to negative
num.isBetween(value1, value2);        // checks range
num.roundToDecimals(decimalPlaces);   // rounds to N decimals
double.asRadians;                      // degrees โ†’ radians
double.asDegrees;                      // radians โ†’ degrees
T.maxim(upperBound);                  // clamp to upper bound
T.minm(lowerBound);                   // clamp to lower bound
num.orZero;                            // value or 0 if null
num.orOne;                             // value or 1 if null
num.or(value);                         // value or fallback if null

Utility Conversion

double.isWhole;                            // checks if whole number
double.roundToPrecision(nthPosition);     // rounds to N decimal places
bool.isCloseTo(other, precision: 1e-8);  // checks approximate equality
double.randomDouble();                    // random double 0.0โ€“1.0
int Duration.inYears;                    // whole years in duration
bool Duration.isInYears;                 // duration โ‰ฅ one year?
int Duration.absoluteSeconds;            // seconds after whole minutes
Map << MapEntry(key, value);        // insert entry via << operator
Map.toJson();                       // map โ†’ JSON string

Conclusion

dart_extensions_pro is an essential toolkit for any Flutter or Dart developer. With 271+ extensions covering strings, dates, lists, navigation, gestures, colors, numbers, and more, it dramatically reduces boilerplate and makes your codebase cleaner and more expressive. Whether you're a beginner or a seasoned developer, this package is a valuable addition to your stack.

For full documentation and extension list, check it out on pub.dev and GitHub.