common_mobile is a Dart package designed to provide a collection of utility extensions, widgets, and functions to enhance and simplify Flutter development.
This package includes the following features:
- DedeAlign: A set of widgets to control alignment within a parent widget.
- DedePadding: A set of widgets to apply padding to other widgets.
- DedeSafeSpace: A set of widgets to manage safe spaces (e.g., status bar, navigation bar) in your layout.
- DedeSafe: A wrapper to easily manage the safe areas of your layout.
- DedeSpace: A utility to add space between widgets.
-
ShortcutsOnBuildContextExtension: Provides shortcuts for accessing common
BuildContextproperties.themeData: Shortcut forTheme.of(context).mediaQuery: Shortcut forMediaQuery.of(context).safe: Shortcut for accessing safe area insets.scaffold: Shortcut for accessing theScaffoldStatefrom the context.
-
UnfocusOnBuildContextExtension: Provides a method to unfocus the current focus node.
unfocus(): Unfocus the current focus node.
- PartitionOnIterableExtension: Partitions elements of an
Iterableinto smaller lists of a specified size.partition(int size): Partitions elements into lists of the specified size.
- SeparateOnListExtension: Inserts a separator between each element in a list.
separate(T separator): Returns a new list with separators between elements.
-
DurationOnIntExtension: Easily create
Durationobjects from integers.microseconds,milliseconds,seconds,minutes,hours,days,weeks,months,years: Methods to createDurationobjects.
-
InvertedIndexOnIntExtension: Calculates the inverted index of an integer.
invertedIndex(int n): Returns the inverted index.
-
ModuloLessThanOnNumExtension: Performs a modulo operation ensuring the result is always less than the divisor.
moduloLessThan(num divisor): Returns the modulo of the number with the given divisor.
-
RangeOnNumExtension: Maps a number from one range to another.
mapToRangeFrom((double toMin, double toMax), [(double fromMin, double fromMax)]): Maps a value from one range to another.
- ToColorOnStringExtension: Converts a hex string to a
Colorobject.toColor({String alphaChannel = 'FF'}): Converts a hex string to aColor.
-
AlignOnWidgetExtension: Provides methods to align widgets within their parent.
alignBottomCenter(),alignBottomLeft(),alignBottomRight(),alignCenter(),alignCenterLeft(),alignCenterRight(),alignTopCenter(),alignTopLeft(),alignTopRight(): Aligns the widget within its parent.
-
PaddingOnWidgetExtension: Provides methods to apply padding to widgets.
withPadding(...),withAllPadding(...),withTopPadding(...),withBottomPadding(...),withLeftPadding(...),withRightPadding(...),withHorizontalPadding(...),withVerticalPadding(...): Adds padding to the widget.
-
SafeAreaOnWidgetExtension: Wraps the widget with
SafeAreato respect safe area insets.withSafeArea(...),withSafeAreaNone(),withSafeAreaTop(),withSafeAreaBottom(),withSafeAreaLeft(),withSafeAreaRight(),withSafeAreaVertical(),withSafeAreaHorizontal(),withSafeAreaAll(): Wraps the widget withSafeArea.
-
BorderRadiusOnWidgetExtension: Adds circular border radius to a widget.
withCircularBorderRadius(double radius): Wraps the widget with aContainerthat has a circular border radius.
-
Loading Overlay Hook:
- useLoadingOverlay: A hook to manage loading overlay in your Flutter application.
- LoadingOverlay: A widget that displays a loading overlay.
-
useWireframeInputDecoration: A hook to create wireframe-style
InputDecorationobjects. -
useWireframeTextFieldTextStyle: A hook to create wireframe-style
TextStylefor TextField objects.
-
Color Utilities:
hexToColor(String hexString, {String alphaChannel = 'FF'}): Converts a hex color string to aColor.
-
Partition Utilities:
PartitionIterator: An iterator to iterate over partitions of a list.Partition: A utility class to partition an iterable into smaller lists.
Add the following line to your pubspec.yaml:
common_mobile:
git:
url: https://github.com/dedecube/common-mobile
ref: mainYou can set as ref the desired version, using a tag or a commit hash.
Then, run flutter pub get in your terminal.
You can import the package and use the provided utilities as follows:
import 'package:common_mobile/common_mobile.dart';
// Example: Using an extension to align a widget
Widget myWidget = Container().alignCenter();
// Example: Partitioning a list
final numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
final partitioned = numbers.partition(3);
print(partitioned); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]Contributions are welcome! Please feel free to submit a pull request or open an issue.
This package is licensed under the MIT License. See the LICENSE file for more details.