mayr_flutter_extensions 1.0.0
mayr_flutter_extensions: ^1.0.0 copied to clipboard
A comprehensive set of handy Flutter-specific extensions to make your Flutter code cleaner, shorter, and more expressive. Works alongside mayr_dart_extensions for complete functionality.
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.0 - 2025-01-17 #
π Initial Release #
This is the first release of mayr_flutter_extensions as a standalone Flutter-specific extension package, separated from the original mayr_extensions package.
Added - New Extensions #
π¨ Widget Extensions - Positioning & Sizing
positioned({top, bottom, left, right})- Wraps widget in Positioned with custom positioning for Stack layoutsaspectRatio(double ratio)- Maintains aspect ratio (e.g., 16:9 for videos)fractionallySizedBox({widthFactor, heightFactor})- Sizes widget as fraction of parent
π¨ Widget Extensions - Styling
decorated(BoxDecoration decoration)- Wraps widget in DecoratedBox with custom decorationcard({elevation, shape})- Wraps widget in Material CardclipOval()- Clips widget to oval shape
π¨ Widget Extensions - Layout
scrollable({direction})- Wraps widget in SingleChildScrollView (vertical or horizontal)safeArea({top, bottom})- Wraps widget in SafeArea with optional sidesfittedBox({fit})- Wraps widget in FittedBox with BoxFit options
π¨ Widget Extensions - Effects & Gestures
hero(String tag)- Wraps widget in Hero for page transition animationsrotated(int quarterTurns)- Wraps widget in RotatedBox (rotates by 90Β° increments)transform(Matrix4 transform)- Wraps widget in Transform with matrix transformationsgestureDetector({onTap, onDoubleTap})- Wraps widget in GestureDetector for gesture handlingdismissible(Key key, {direction})- Wraps widget in Dismissible for swipe-to-dismiss functionality
π§ BuildContext Extensions - Navigation
push(Widget page)- Navigate to new page with MaterialPageRoutepop([result])- Go back with optional resultpushReplacement(Widget page)- Replace current route with new pagepushNamed(String route, {arguments})- Navigate by named route with arguments
π§ BuildContext Extensions - Theme Access
theme- Get current ThemeDataprimaryColor- Quick access to theme primary colorcolorScheme- Access current ColorSchemetextTheme- Access TextTheme stylesisDarkMode- Check if dark mode is active (based on theme brightness)
π§ BuildContext Extensions - MediaQuery Shortcuts
screenWidth/screenHeight- Convenient aliases for screen dimensionspadding- Get safe area insets (notch, status bar, etc.)viewInsets- Get system UI insets (keyboard, navigation bar, etc.)devicePixelRatio- Get device pixel density
π§ BuildContext Extensions - Platform Detection
isIOS- Check if running on iOS platformisAndroid- Check if running on Android platformisWeb- Check if running on web platform (useskIsWebconstant)
π§ BuildContext Extensions - Dialogs
showCustomDialog(Widget dialog)- Show Material dialog with less boilerplateshowSheet(Widget content)- Show modal bottom sheet with less boilerplate
π§ String Extensions
toText({style})- Convert String to Text widgettoSelectableText({style})- Convert String to SelectableText widget
π§ List
toColumn({mainAxisAlignment, mainAxisSize, crossAxisAlignment})- Convert widget list to ColumntoRow({mainAxisAlignment, mainAxisSize, crossAxisAlignment})- Convert widget list to RowtoStack({alignment, fit})- Convert widget list to StacktoWrap({alignment, runAlignment, spacing, runSpacing})- Convert widget list to Wrap
π¨ Color Extensions
withOpacity(double opacity)- Create color with specified opacitydarken([double amount])- Make color darker using HSL color space (default 10%)lighten([double amount])- Make color lighter using HSL color space (default 10%)
π EdgeInsets Extensions
horizontal- Get total horizontal padding (left + right)vertical- Get total vertical padding (top + bottom)all- Get uniform padding value (if all sides are equal)copyWith({left, top, right, bottom})- Create modified copy of EdgeInsets
Package Philosophy #
This package is part of the MayR Extensions family:
- mayr_dart_extensions - General Dart extensions (String, int, DateTime, Duration, List, Map, etc.)
- mayr_flutter_extensions - Flutter-specific extensions (Widget, BuildContext, etc.)
This separation ensures:
- Pure Dart projects can use general extensions without Flutter dependencies
- Flutter projects can use both packages together for complete functionality
- No code duplication between packages
- Cleaner, more focused codebases
Features #
π§± BuildContext Extensions
- Navigation & State Access:
navigator,scaffold,form,overlay,scaffoldMessenger - SnackBar Helper:
showSnackBar()for quick snackbar display - Media Query:
mediaQuery,widgetSize,widgetWidth,widgetHeight,widgetShortestSide - Theme & Brightness:
platformBrightness,platformInDarkMode,platformInLightMode - Device Detection:
orientation,isPortrait,isLandscape,isPhone,isSmallTablet,isLargeTablet,isTablet,isDesktop
π¨ Widget Extensions
- Basic Transformations:
center(),expanded(),flexible(),opacity(),sizedBox(),constrained() - Padding:
paddingAll(),paddingSymmetric(),paddingOnly(),paddingZero() - Clipping:
clipRect(),clipRRect(),clipRounded() - Positioning:
positionAlign(),positionedFill() - Visibility Helpers:
showIf(),hideIf(),showUnless(),hideUnless()
π Tap Interactions
- InkWellManager: Helper class for cleaner tap handling
inkWellManager()- Setup tap handleronTap()- Single taponDoubleTap()- Double taponLongPress()- Long press
πΌοΈ Image Extensions
circleAvatar()- Convert Image to CircleAvatar with customization options
Changed from Original Package #
Removed (Now in mayr_dart_extensions)
- Bool extensions (choose, toInt, toYesNo, not)
- String extensions (camelCase, snakeCase, mask, isEmail, etc.)
- Number extensions (clampMin, clampMax, formatAsCurrency, etc.)
- DateTime extensions (addDays, format, toAge, etc.)
- Duration extensions (delay, toReadableString, etc.)
- List/Iterable extensions (firstOrNull, chunked, mapIndexed, etc.)
- Map extensions (getOrNull, mapKeys, merge, etc.)
- Set extensions (toggle, intersects, isSubsetOf, etc.)
- Object extensions (let, also)
- Dynamic extensions (nullOnDebug, maybe, orDefault)
- Humanize extensions (humanizeNumber, humanizeOrdinal, etc.)
- MayrDateTimeFormats utility class
Migration Guide #
If you were using the original mayr_extensions package:
-
Install both packages:
dependencies: mayr_dart_extensions: ^1.0.0 mayr_flutter_extensions: ^1.0.0 -
Update imports:
// For general Dart extensions import 'package:mayr_dart_extensions/mayr_dart_extensions.dart'; // For Flutter-specific extensions import 'package:mayr_flutter_extensions/mayr_flutter_extensions.dart'; -
No code changes needed - All extensions work the same way, they're just in different packages now!
For older versions, see the history of the original mayr_extensions package.