flutter_helper_utils 6.0.2 flutter_helper_utils: ^6.0.2 copied to clipboard
The Flutter Helper Utils Package offers various extensions and helper methods that can make development more efficient.
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.
This package enhances ValueNotifier
with additional functionalities:
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
.builder
extension on anyValueListenable
,Listenable
, orList<Listenable>
instance to create aValueListenableBuilder
,ListenableBuilder
, orListenablesBuilder
respectively under the hood with a shorter and 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 infor
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:
Listenable & ValueNotifier #
on ValueListenable #
builder
: Simplifies the creation of aValueListenableBuilder
widget that reacts to changes in a singleValueListenable
.-
final intNotifer = 0.notifer; scrollController.builder((value) => /* widget reacts to intNotifer changes */ );
-
on Listenable #
.builder
: Simplifies the creation of aListenableBuilder
widget that reacts to changes in anyListenable
.-
final scrollController = ScrollController(); scrollController.builder((context) => /* widget reacts to scrollController changes */ );
-
on List
.builder
: Creates aListenablesBuilder
widget to efficiently manage and respond to changes in multipleListenable
objects simultaneously, includingValueNotifier
,ChangeNotifier
, and others. Customize rebuild behavior using the optionalbuildWhen
andthreshold
parameters.-
final myListeners = <Listenable>[textController, scrollController, anyNotifier]; myListeners.builder((context) => /* widget reacts to myListeners changes */ );
-
ValueNotifier Creation #
.notifier
: Converts a value of any type into the correspondingValueNotifier
type/subtype, enabling easy integration into reactive UI components.- e.g.
final intNotifer = 1.notifier
creates an IntNotifier aka ValueNotifier
- e.g.
UI & Design #
Colors #
toHex
: Transforms aColor
object into its corresponding hexadecimal string representation.toColor
: Creates aColor
object from a valid hexadecimal color string.isHexColor
: Determines if a given string is a valid hexadecimal color representation.
ThemeData #
isDark
,isLight
: Checks whether the current theme is in dark or light mode.textTheme
: Provides direct access to theTextTheme
of the current theme.displayLarge
,displayMedium
,displaySmall
, etc.: Retrieve specific text styles from the theme, optimized for different display sizes.displayLargeCopy
,displayMediumCopy
,displaySmallCopy
, etc.: Retrieve copies of the specific text styles from the theme, allowing modifications without affecting the original 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.