mabe_utils 0.2.0-pre copy "mabe_utils: ^0.2.0-pre" to clipboard
mabe_utils: ^0.2.0-pre copied to clipboard

Utility widgets, extension methods and types used on every app developed by me (https://raulmabe.dev)

Mabe Utils #


style: very good analysis Powered by Mason License: MIT

Utils Code by MABE

Installation 💻 #

❗ In order to start using Mabe Utils you must have the Flutter SDK installed on your machine.

Install via flutter pub add:

dart pub add mabe_utils

Widgets #

Look at the example folder to check how to work with these widgets.

  • MabeOverlay
    • MabeOverlay is a StatefulWidget that creates a custom overlay widget. It allows for the display of an overlay widget above other widgets, with customizable positioning and behavior.
  • Storyboard
    • Scaffold for Instagram Stories like content.
  • DetectTextOverflowBuilder
    • Exposes a itemBuilder to build a widget based on if text rendered has exceeded its space. It doesn't actually render the Text on the screen.
  • AppLifeCycleListener
    • Exposes callbacks for every life cycle method of the app (onResumed, onBackground, onPause, etc.)
  • ReactOnTap
    • Scale
    • Opacity [Pending]
  • Disabled
    • Marks child as disabled by reducing its opacity to half and ignoring pointers.
  • KeyboardHeightProvider
    • When added to the widget tree, keeps track of the keyboard height and provides these values through the context via context.maxKeyboardHeight or context.keyboardHeight
  • LoadingManager
    • Adds an overlay on top of all the sub-widget tree when loading. Allows to add loading tasks
  • AlertManager
    • AlertManager which provides functionality to add or remove alerts above the sub-widget tree. Use it like context.alert(msg: msg)

Mixins #

  • RouteAwareSubscriptionMixin - Usage
    • Add a provider, and a mixin and automatically subscribes/unsubscribes to the Flutter Navigation. This allows to override methods like didPop or didPush.

Types #

/// Map of keys and values of type String
typedef StringMap = Map<String, String>;

/// Map of String keys and dynamic values.
typedef JSON = Map<String, dynamic>;

/// [VoidCallback] that returns a [Future]
typedef FutureVoidCallback = Future<void> Function();

/// Callback that accepts an [int] through parameters
typedef IntCallback = void Function(int);

/// Callback that accepts an [String] through parameters
typedef StringCallback = void Function(String value);

/// Callback that accepts an [BuildContext] through parameters
typedef VoidContextCallback = void Function(BuildContext context);

/// Callback for bottomsheet builders
typedef BottomSheetBuilder = Future<T?> Function<T>(Widget child);

Extensions #

Iterables & Lists

List<Widget> borderRadius(double radius);

List<T> removeNull();

List<T> reverseIf(bool b);

T after(T value);

List<T> separateBy(T separator, {bool wrap = false});

Iterable<T> hugBy(T hugger);

Iterable<S> indexedMap<S>(S Function(T item, int index) map);

Iterable<T> putIfAbsent(T value, {EqualityBuilder<T>? equalityBuilder});

/// Adds or removes the [value] based on if the value was already in.
List<T> toggle(T value);

/// Returns `true` if the iterable is has an element of type [S].
bool anyType<S extends T>();

/// Extract one random item from the list
T random();

/// Extract random items from the list
List<T> randomSublist(int count);

/// The contrary version of [whereType]. Returns a new
/// list composed of only the elements that are **NOT** of type [S].
List<T> whereTypeNot<S extends T>();

/// Same as [whereType] but with a pair of types.
List<T> whereTypes<S extends T, R extends T>();

/// The first element satisfying [test], or `null` if there are none.
T? firstWhereOrNull(bool Function(T element) test);

/// Returns the last element, and returns null on empty.
T? get lastOrNull;

/// Returns the first element, and returns null on empty.
T? get firstOrNull;

/// Returns a map groupped by the [keyFunction].
Map<K, List<T>> groupBy<K>(K Function(T) keyFunction);

/// Returns the element at position [index] % [length].
T loop(int index);

/// Returns the element at index [i] if present. Returns null otherwise
T? elementAtOrNull(int i);

/// Contiguous slices of `this` with the given [length].
///
/// Each slice is [length] elements long, except for the last one which may be
/// shorter if `this` contains too few elements. Each slice begins after the
/// last one ends. The [length] must be greater than zero.
///
/// For example, `{1, 2, 3, 4, 5}.slices(2)` returns `([1, 2], [3, 4], [5])`.
Iterable<List<T>> slices(int length);

Context

  /// Equivalent as `Navigator.of(context)`
  NavigatorState get navigator => Navigator.of(this);

  /// Equivalent as `MediaQuery.sizeOf(context)`
  Size get screen => MediaQuery.sizeOf(this);

  /// Equivalent as `MediaQuery.of(context)`
  MediaQueryData get mediaQuery => MediaQuery.of(this);

  /// Returns padding for the nearest MediaQuery ancestor or
  /// throws an exception, if no such ancestor exists.
  EdgeInsets get padding => MediaQuery.paddingOf(this);

  /// Equivalent as `Theme.of(context)`
  ThemeData get theme => Theme.of(this);

  /// Returns the current [LayoutBreakpoint] based on screen device size.
  LayoutBreakpoint get breakpoint;

  /// Returns `true` if screen device size is [LayoutBreakpoint.mobile]
  bool get isMobile;

  /// Returns `true` if screen device size is [LayoutBreakpoint.tablet]
  bool get isTablet;

  /// Returns `true` if screen device size is [LayoutBreakpoint.desktop]
  bool get isDesktop;

  /// Returns a ValueNotifier that fires everytime
  /// the **max** keyboard height changes.
  ValueNotifier<double> get maxKeyboardHeight;

  /// Returns a ValueNotifier that fires everytime the keyboard height changes.
  ValueNotifier<double> get keyboardHeight;

  /// Returns the closest [KeyboardHeightProvider] to the tree if any,
  KeyboardHeightProviderState? get maybeKeyboardHeightProvider;

  // * Managers
  /// Adds an overlay while this task is being executed.
  void showLoading({required String tag, String? message});

  /// Removes the tasks, and subsequently the loading overlay.
  void hideLoading({required String tag});

  /// Adds a new alert.
  void alert({
    required String msg,
    AlertType? type,
    String? id,
    Duration? duration,
  });

  /// It shows a Dialog and will the corresponding [AppDialogAction].
  Future<AppDialogAction> popup(
    Widget dialog, {
    Color? barrierColor,
    bool? isDismissable,
  });

	/// Same as [bottomsheet] but with a widget builder.
  Future<T?> bottomsheetBuilder<T>(WidgetBuilder builder,{Color? barrierColor});

  /// Shows a BottomSheet with [child] as a child.
  Future<T?> bottomsheet<T>(Widget child, {Color? barrierColor});

GlobalKey

 	/// Returns the global offset of the widget attached to this key.
  Offset? get offset;

  /// Returns the size of the widget attached to this key.
  Size? get size;

  /// Returns a Rect of this widget based on the global offset and its size.
  Rect? get rect;

String

 Color get color;

	/// Returns the initial letter of each word
  String get initials;

  /// Returns the same string but the first letter is uppercase.
  String get capitalized;

  /// Transforms a camel case to a sentence case.
  /// Example: camelToSentence -> Camel To Sentence
  String get camelCaseToSentenceCase;

And more ✨

0
likes
140
pub points
0%
popularity

Publisher

verified publisherraulmabe.dev

Utility widgets, extension methods and types used on every app developed by me (https://raulmabe.dev)

Repository (GitHub)
View/report issues

Topics

#utils #extensions #widget #types

Documentation

Documentation
API reference

License

MIT (LICENSE)

Dependencies

figma_squircle, flutter, gap, modal_bottom_sheet, provider, sprung

More

Packages that depend on mabe_utils