mayr_extensions 1.0.1
mayr_extensions: ^1.0.1 copied to clipboard
A comprehensive set of handy Dart and Flutter extensions to make your code cleaner, shorter, and more expressive.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.0.1 Doc Fix #
Improved #
- Reverted the documentation for the package back to the README.md as the doc/ was not getting linked by pub.dev
1.0.0 Major Release with New Extensions #
Added #
Iterable/List Extensions
-
Query & Search:
firstOrNull()- Returns first element ornullif emptylastOrNull()- Returns last element ornullif emptysingleWhereOrNull(predicate)- Returns match ornullcontainsWhere(predicate)- Boolean checkindexWhereOrNull(predicate)- Returns index ornull
-
Safe Access:
getOrNull(index)- Returns element at index ornullgetOrDefault(index, defaultValue)- Returns element or default value
-
Transformations:
chunked(size)- Splits into chunksmapIndexed((index, item) => ...)- Maps with indexwhereNotNull()- Filters out nullsdistinctBy(keySelector)- Unique items by propertyflatten()- Flattens nested listssortedBy(keySelector)/sortedByDesc(keySelector)- Sort by propertyflip()- Reverses the list
-
Aggregations (for numbers):
sumBy(num Function(T))- Sum elements by selectoraverageBy(num Function(T))- Average by selectorcountWhere(predicate)- Count matching elements
-
Mutation Helpers (returns new copy):
insertIf(condition, value)- Insert conditionallyreplaceWhere(predicate, newValue)- Replace matching elementsremoveWhereNot(predicate)- Keep only matching elementsupdateWhere(predicate, updater)- Update matching elementsaddIf(value)/addAllIf(values)- Add conditionallyappend(value)/appendAll(values)- Append elementsappendIf(value)/appendAllIf(values)- Append conditionallypop()- Remove and return last elementfliter(predicate)- Filter elements (alias for where)unique()- Get unique elements
-
Utility:
isNullOrEmpty()- Check if emptyjoinToString(separator, transform)- Join with custom formatforEachIndexed()- Iterate with index
Map Extensions
-
Safe Access:
getOrNull(key)- Get value or nullgetOrDefault(key, defaultValue)- Get value or default
-
Transformations:
mapKeys((k, v) => newKey)- Transform keysmapValues((k, v) => newValue)- Transform valuesfilterKeys(predicate)- Filter by keysfilterValues(predicate)- Filter by valuesinvert()- Swap keys and values
-
Merge & Combine:
merge(otherMap)- Merge with precedencemergeIfAbsent(otherMap)- Merge without overridingcombine(other, (k, v1, v2) => mergedValue)- Custom merge
-
Utility:
keysWhere(predicate)- Get keys matching predicatevaluesWhere(predicate)- Get values matching predicatetoQueryString()- Convert to URL query string
Set Extensions
toggle(element)- Add if missing, remove if presentintersects(otherSet)- Check for intersectionisSubsetOf(otherSet)- Check if subsetisSupersetOf(otherSet)- Check if supersetunionAll(sets)- Union of multiple setswithout(element)- Remove element
Humanize Extensions
-
Duration:
humanize(locale)- Convert to "2 hours, 3 minutes" format
-
DateTime:
humanize(locale)- Convert to relative time ("just now", "3 hours ago", "yesterday", "last week", etc.)
-
Numbers:
humanizeNumber()- Format as "15.3k", "1.5M", etc.humanizeOrdinal()- Format as "1st", "2nd", "3rd", etc.humanizeCount('item')- Format as "1 item" / "3 items"humanizePercentage(max, min)- Format as "74%"humanizeFileSize()- Format as "1.0 MB", "520.3 KB", etc.
Changed #
- Updated package version to 1.0.0 marking stable release
Improved #
- Added comprehensive test coverage for all new extensions
- Complete documentation with examples for all methods
- Enhanced type safety with proper generic constraints
[Unreleased] #
Improved #
- Added comprehensive test coverage for DateTime extensions
- Tests for all manipulation methods (addDays, addMonths, addYears, subDays, etc.)
- Tests for check methods (isToday, isTomorrow, isYesterday, isInFuture, isInPast)
- Tests for formatting methods (format, toTimeString, toShortDate, toDayOrdinal)
- Tests for time of day checks (isMorning, isAfternoon, isEvening, isNight)
- Tests for age calculations (toAge, isAgeOlder, isAgeYounger, isAgeBetween)
0.4.0 6th October, 2025 #
Added #
-
String Extensions:
reverse()- Reverses the stringisBlankandisNotBlank- Check if string is empty or contains only whitespaceremoveWhitespace()- Removes all whitespace from the stringcountOccurrences(substring)- Counts occurrences of a substringtruncate(maxLength)- Truncates with word boundary awarenesswrap(prefix, suffix)- Wraps string with prefix and suffixremovePrefix(prefix)andremoveSuffix(suffix)- Remove specific prefix or suffix
-
Number Extensions:
toDecimalPlaces(places)- Rounds double to specified decimal placesisBetween(min, max)- Checks if number is within rangeisPositive,isNegativeNumber,isZero- Number sign checksisEvenNumberandisOddNumber- Parity checks for integerstimes(action)- Repeat an action n timestimesIndexed(action)- Repeat an action n times with index
-
Bool Extensions:
choose(trueValue, falseValue)- Select value based on booleantoInt()- Convert to integer (1 for true, 0 for false)toYesNo()- Convert to string with customizable true/false valuesnot- Returns the negation of the boolean
-
Duration Extensions:
toReadableString()- Human-readable duration format (e.g., '2h 30m')isLongerThan(other)- Compare durationsisShorterThan(other)- Compare durations
-
Object Extensions:
let(transform)- Transform object inline with functionalso(action)- Execute side effects while maintaining object for chaining
Changed #
- Enhanced all extension methods with comprehensive dartdoc documentation
- Improved code comments and examples throughout
- Applied DRY (Don't Repeat Yourself) principle by consolidating common patterns
- Enhanced modularity by ensuring each extension has a single responsibility (SRP)
Improved #
- Added extensive test coverage for all new methods
- Documentation now includes usage examples for better developer experience
- Code structure follows KISS (Keep It Simple, Stupid) principle
- Enhanced Dynamic/Nullable extensions with better documentation
0.3.1 #
- Automated deployments
0.3.0 30th April, 2025 #
Added #
context.platformInLightModedateTime.startOfDay()MayrDateTimeFormats: A collection of popular datetime formats- Slightly more tests and dartdocs
Changed #
dateTime.toFormat(...)->dateTime.format(...)dateTime.isYesterday(),dateTime.isToday(), anddateTime.isTomorrow()are now getter properties:dateTime.isYesterdaydateTime.isTodaydateTime.isTomorrow
dateTime.isInPast()anddateTime.isInFuture()are also now getter properties:dateTime.isInPastdateTime.isInFuture
Removed #
dateTime.toDateString(...)dateTime.toDateStringUK(...)dateTime.toDateStringUS(...)dateTime.toDateTimeString(...)dateTime.isExpired()
0.2.0 [29-04-2025] #
Added #
T?.orDefault(T fallback)AddedString.copyToClipboard()AddedString.toUri()Added- More dartdocs to properties and methods
Changed #
String.toDateTime()now uses tryParse, so null is returned if parse fails and error is not thrown- Added namespaces to extensions to prevent clash with user extensions
0.1.1 Minor cleanups #
Changed #
- Removed certain files that are not required to use package from pub
0.1.0 Rebrand to mayr_* #
Changed #
- Package name was rebranded from
flutter_util_extensionstomayr_extensions
0.0.1 Initial Release #
Added #
- BuildContext extensions:
- Access to form, navigator, overlay, scaffold, media query, brightness, platform checks, and widget size.
- Device type checks (phone, tablet, desktop).
- Added
showSnackBar()utility method.
- DateTime extensions:
- Checkers for time of day, expiry, and comparisons.
- Manipulators to add/subtract dates, months, years, etc.
- Conversions to various string formats and age calculation.
- Duration extension:
delay()method for simple async delays.
- Dynamic extensions:
nullOnDebug(),onlyOnDebug(), andmaybe()based on probability.
- Image extension:
- Easily create a
CircleAvatarwidget with an image.
- Easily create a
- Number extensions:
- Comparison helpers, random number generators, number formatters, and conversions to Duration.
- String extensions:
- Pattern matching, parsing to different cases (camelCase, snakeCase, etc.), and pretty printing (JSON, YAML, XML).
- Pattern checkers for emails, URLs, IP addresses, and more.
- Widget extensions:
- Helpers for padding, sizing, positioning, clipping, visibility, and touch management via
InkWellManager.
- Helpers for padding, sizing, positioning, clipping, visibility, and touch management via
Notes #
- First public release.
- Still evolving — contributions and feedback welcome!