extensions_core 0.0.4 copy "extensions_core: ^0.0.4" to clipboard
extensions_core: ^0.0.4 copied to clipboard

Extensions for dart and flutter

Extensions Core #

A comprehensive, dependency-light collection of Dart & Flutter extensions.

Stop hunting for separate extension packages — extensions_core covers the daily-driver utilities across strings, numbers, dates, collections, colors, widgets, navigation, and more in one place.

Dart Flutter License


Table of Contents #


Installation #

Add the package to your pubspec.yaml:

dependencies:
  extensions_core: ^0.0.4

Then run:

flutter pub get

Requirements: Dart ^3.6.0 · Flutter >=3.27.0


Quick Start #

import 'package:extensions_core/extensions.dart';

void main() {
  // Strings
  'hello world'.toCamelCase();      // helloWorld
  'hello world'.toSnakeCase();      // hello_world
  'user@site.com'.isEmail();        // true

  // Iterables
  [1, 2, 3, 4].sum;                 // 10
  [1, 2, 3].zip(['a', 'b']);        // [(1, a), (2, b)]

  // Colors
  colorFromHex('#2196f3').toHex();  // #ff2196f3

  // Dates
  DateTime.now().startOfWeek;       // Monday
}

Extension Collections #

Object #

Extension Description
let<R>(R Function(T)) Pass this to a function, return its result.
also(void Function(T)) Run a side effect, return this.
run<R>(R Function(T)) Alias of let.
isNull / isNotNull Null checks on any nullable value.
final length = 'hello'.let((s) => s.length); // 5
String? maybe;
maybe.isNull; // true

String #

Validation: isEmail · isUrl · isPhoneNumber · isNumeric · isAlphabetic · isAlphanumeric · containsUppercase · containsLowercase · containsDigit · containsSpecialCharacter · isStrongPassword · isJson

Parsing: toIntSafe · toDoubleSafe · toBool · isNullOrEmpty (nullable) · isNullOrWhiteSpace

Case: capitalize · toTitleCase · toCamelCase · toPascalCase · toSnakeCase · toKebabCase

Slicing: truncate · reverse · removeWhitespace · collapseWhitespace · before · after · between · replaceLast · countOccurrences · initials · masked · onlyDigits · withoutDigits · slugify

'john_smith'.toCamelCase();      // johnSmith
'John Smith'.initials();         // JS
'hello'.masked();                // *ello

Number & Int #

Formatting: toCurrency · toCompact · toPercentage · toDecimal · formatBytes

Predicates: isPositive · isZero · isDivisibleBy · percentageOf · isEven · isOdd (int)

Conversions: ordinal (int) · toBinary · toOctal · toHex (int) · milliseconds/seconds/minutes/hours/daysDuration · heightBox/widthBoxSizedBox · toRadians · toDegrees · isBetween · clamp

1.ordinal();              // 1st
5.toBinary();             // 101
1024.formatBytes();       // 1.00 KB
10.heightBox;             // SizedBox(height: 10)
12.minutes;               // Duration(minutes: 12)

Double #

toFixed(int fractionDigits) · lerp(other, t)

3.14159.toFixed(2);              // 3.14
10.0.lerp(20.0, 0.5);            // 15.0

DateTime #

Checks: isToday · isYesterday · isTomorrow · isSameDay · isSameMonth · isSameYear · isBetween · isWeekend · isWeekday · isLeapYear · isInFuture · isInPast

Boundaries: startOfDay/endOfDay · startOfWeek/endOfWeek · startOfMonth/endOfMonth · startOfYear/endOfYear · tomorrow · yesterday

Helpers: copyWith · ageInYears · quarter Formatting: format · formattedDate · timeAgo

final now = DateTime.now();
now.startOfMonth;          // 1st of the month
now.ageInYears();          // whole years
now.timeAgo(context);      // "5 minutes ago"

Duration #

inWeeks · format()

const Duration(hours: 2, minutes: 3, seconds: 45).format(); // 2:03:45

Iterable #

Selection: firstWhereOrNull · distinctBy · countWhere · containsAll · containsAny

Math (Iterable<num>): sum · min · max · average; plus sumBy · averageBy

Grouping/joining: groupBy · insertBetween · zip · unzip · flatten

List #

isNullOrEmpty · takeLast · takeFirst · chunked · reversedList · rotate · distinct · whereNotNull · shuffledList · mapToList · safeGet · hasUniqueElements

[1, 2, 3, 4, 5].rotate(2);   // [4, 5, 1, 2, 3]
[1, 2, 3].chunked(2);        // [[1, 2], [3]]

Map #

getOrElse · getOrPut · deepMerge · merge · invert · where · filterKeys · filterValues · mapKeys · mapValues · pick · omit · keysOf

{'a': 1, 'b': 2}.invert();               // {1: a, 2: b}
{'a': 1, 'b': 2, 'c': 3}.pick(['a', 'c']); // {a: 1, c: 3}

Color #

Conversion: toHex · colorFromHex(String) (top-level function)

Shading: darken · lighten · blend · inverse · complementary

Properties: hue · saturation · brightness · withBrightness · isDark · isLight · isTransparent · toMaterialColor

colorFromHex('#f00').lighten(0.2);
Colors.red.complementary;   // cyan
Colors.red.toMaterialColor();

BuildContext #

Media: screenWidth · screenHeight · screenSize · viewInsets · viewPadding · safePadding · mediaQuery · devicePixelRatio · textScaler · orientation · isPortrait · isLandscape · hideKeyboard

Device/Theme: isMobile · isTablet · isDesktop · theme · textTheme · colorScheme · primaryColor · accentColor · scaffoldBackgroundColor · iconTheme · locale · textDirection

if (context.isTablet) { /* ... */ }
context.hideKeyboard();

Widget #

Layout: padding · margin · background · border · center · expanded · flexible · align · size · width · height · constrained · aspectRatio

Interaction: onTap · onLongPress · onDoubleTap · inkWell · tooltip

Effect: opacity · visible · safeArea · circular · elevated · blur · rotated · scaled

Text('Hello').padding().background(Colors.red).tooltip('hi');
Text('Tap').inkWell(onTap);

TextStyle #

size · scaleSize · weight · bold · semiBold · light · medium · color · letterSpacing · wordSpacing · italic · lineHeight · backgroundColor · underline · lineThrough · overline · noDecoration · decorationThickness · mergeWith · fontFamily · withShadow · withShadows · glow · responsiveSize · outlined

TextStyle().bold.color(Colors.red).size(24);

Icon #

withColor(Color) · withSize(double)

Image #

toBase64() · withFilter(ColorFilter)

File #

sizeBytes · sizeFormatted · sizeInMB · isImage · isVideo · isAudio · readAsStringSafe

File('photo.jpg').isImage;   // true
file.sizeFormatted();        // "1.23 MB"

EdgeInsets #

copyWith({left, top, right, bottom}) — Flutter's EdgeInsets has none.

State #

safeSetState(fn) — calls setState only while the widget is mounted.

Platform #

On BuildContext: platform and targetPlatform expose isAndroid, isIOS, isWeb, isMacOS, isWindows, isLinux, isFuchsia.

Transitions: navigateTo · navigateBack · navigateToReplace · navigateAndRestore · navigateAndRemoveUntil · pushScreen · pushWithFade · pushWithSlide · replaceScreen

Stack: clearStackAndShow · popUntilRoute · popToFirst · canPop · maybePop · popWithResult · currentRouteName

Presenters: showSheet · showAppDialog

context.pushWithSlide(DetailsScreen());
context.canPop;
context.showSheet(child);

Alert & Snackbar #

showCusDialog(Widget) · showSnackBar(String) · removeSnackBar()

Form Validators #

Composable String? Function(String?) validators, ready for TextFormField:

requiredField · emailValidator · phoneValidator · minLengthValidator · maxLengthValidator

TextFormField(validator: emailValidator);

Examples #

A few pending UI recipes:

// Ripple button with padding and tooltip
Text('Submit').inkWell(() => submit()).padding(EdgeInsets.all(12));

// Slide-in navigation to a screen
context.pushWithSlide(const ProfileScreen());

// Form field with validation
TextFormField(
  controller: _email,
  validator: emailValidator,
  decoration: const InputDecoration(labelText: 'Email'),
);

Contributing #

Contributions are welcome. To keep the package consistent:

  1. Extensions follow the Dart style guide and flutter_lints.
  2. New extensions should be added under lib/extensions/ with a focused file per type, then exported from lib/extensions.dart.
  3. Add tests in test/ — run flutter test and flutter analyze before submitting.
  4. Update this README and the CHANGELOG.md for user-visible changes.

License #

MIT

Copyright © Extensions Core contributors.

0
likes
140
points
2.29k
downloads

Documentation

API reference

Publisher

verified publisherchristhapa.com.np

Weekly Downloads

Extensions for dart and flutter

Homepage

License

MIT (license)

Dependencies

flutter, intl

More

Packages that depend on extensions_core