flutter_helper_utils 4.4.0 flutter_helper_utils: ^4.4.0 copied to clipboard
The Flutter Helper Utils Package offers various extensions and helper methods that can make development more efficient.
Flutter Helper UtilsMake Flutter development easier with Flutter Helper Utils! This toolkit is packed with helper methods and extensions that boost your productivity and help you write less code and build apps faster. |
Important Notes for Version 4.1.0+: We've refactored the Dart-specific utilities into a new package, dart_helper_utils
, to allow Dart projects to use these utilities without depending on Flutter.
- Future updates for Dart-specific utilities will be available in the
dart_helper_utils
changelog. - All the Dart-specific utilities documentations moved to the
dart_helper_utils
readme. - This package already exporting
dart_helper_utils
, so there is no breaking changes on this version.
Table of Contents #
Featured #
ValueNotifier Supercharged #
ValueNotifier is a simple class in Flutter that allows you to store a value and notify any listeners when the value changes.
in this package, I've made this feature event better!
Starting from version 4.0.0, you can use a new set of extensions, helper methods, and specialized notifiers for better data handling:
- Instantly create notifiers from any value with the intuitive
.notifier
extension (e.g.,10.notifier
) - Specific data types using our type-safe notifiers like
ListNotifer
,BoolNotifier
,IntNotifier
, etc. - use the
.listenableBuilder
extension onValueNotifier
instance which creates aValueListenableBuilder
under the hood with shorter/simpler syntax. - complex data handling with collections. For example
ListNotifier
, which acts like normal list andValueNotifier
at the same time, which means you can use it in for loops, inValueListenableBuilder
widget, and get notified automatically when inner data changed. Same goes for all notifier classes!
Example:
final counter = 0.notifier;
counter.listenableBuilder((count) => Text('$count'));
counter.increment(); // Increment the counter easily
For more info about ValueNotifier check the official flutter documentation
Extensions #
All the extensions included in the dart_helper_utils
package Plus:
UI & Design #
Colors #
toHex
: Converts aColor
object to its hex string representation.toColor
: Converts a hex color string to aColor
object.isHexColor
: Validates a string as a hexadecimal color.
ThemeData #
isDark
,isLight
: Check if the theme is dark or light.displayLarge
,displayMedium
,displaySmall
, etc.: Access various text styles defined in the theme.displayLargeCopy
,displayMediumCopy
,displaySmallCopy
, etc.: Access various text styles with copyWith defined in the theme.
BuildContext #
Important Note: Avoid frequent use of context on actions that might call of(context)
like theme. The widget
registers itself as a dependency on the theme, meaning that if the theme changes (e.g., when switching between
light/dark mode), all widgets using Theme.of(context)
aka context.themeData
will rebuild, even if they don’t directly depend on the changed
theme properties. It’s recommended to use final theme = context.themeData
at the top of the widget tree only once.
For Themes #
themeData
: Get the currentThemeData
.txtTheme
: Obtain theTextTheme
.brightness
: Determine the theme's brightness.sysBrightness
: Determine the system's brightness.isDark
,isLight
: Check if the theme is dark or light.
For MediaQuery #
mq
: AccessMediaQueryData
.nullableMQ
: AccessMediaQueryData
(nullable).deviceOrientation
: Get device orientation.navigationMode
: Get navigation mode.padding
,viewInsets
: Get screen padding and insets.screenDimensions
: Get screen width and height.additionalFeatures
: Access additional features.
For FocusScope #
focusScope
: Get the nearestFocusScopeNode
.unFocus
: Remove focus.requestFocus
: Request focus.requestFocusCall
: Request focus (usingGestureTapCallback
).hasFocus
: Check if a node has focus.hasPrimaryFocus
: Check if a node has primary focus.
For Navigation #
popPage
: Pop the current page.popRoot
: Pop to the root page.navigator
: Get theNavigatorState
.canPop
: Check if you can pop the current page.pPage
: Push a new page.pReplacement
: Push and replace the current page.pAndRemoveUntil
: Push and remove pages until a condition is met.pNamedAndRemoveUntil
: Push a named route and remove pages until a condition is met.pNamed
: Push a named route.pReplacementNamed
: Push and replace the current page with a named route.popUntil
: Pop pages until a condition is met.dismissActivePopup
: Dismiss the active popup.
Widgets #
Align #
alignAtBottomCenter
,alignAtTopLeft
,alignAtBottomLeft
, etc.: Align a widget within its parent using various alignment options.alignXY
: Align a widget using explicit x and y coordinates.alignAtLERP
: Align a widget using linear interpolation between two alignments.
Padding #
paddingAll
: Add padding on all sides of a widget.paddingLTRB
: Add padding with individual values for left, top, right, and bottom.paddingSymmetric
: Add padding symmetrically for horizontal and vertical.paddingOnly
: Add padding to specific sides.
More widget extensions to be added soon.
List/Iterable Extensions #
toRow
: Convert a list of widgets into aRow
.toColumn
: Convert a list of widgets into aColumn
.toStack
: Convert a list of widgets into aStack
.toList
: Convert anIterable
to aList
.toListView
: Convert anIterable
to aListView
.
Contributions #
Contributions to this package are welcome. If you have any suggestions, issues, or feature requests, please create a pull request in the repository.
License #
flutter_helper_utils
is available under the BSD 3-Clause License.