Flutter Helper Utils

Make 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.

Flutter Helper Utils Logo

Table of Contents

Featured

Converting Objects:

Convert objects to various types, such as int, double, bool, String, List, Set and Map, They are handy when working with data from APIs, where you often encounter dynamic types. They offer simple and flexible methods to perform accurate type conversions. Here is a sample:

Before:

Map = {score: "12.4"};


int score = double.parse(map['key']).toInt();

Notice that we need to parse to double first then to int.

With Package:


int score = toInt(map['key']);

More Details here

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 .listenableBuilderextension on ValueNotifier instance which creates a ValueListenableBuilder under the hood with shorter/simpler syntax.

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

Our package provides a variety of extensions on Dart and Flutter's built-in types. Below are the categories of available extensions, sorted by their functionalities:

Core Data Types

String Extensions

Number Extensions

Boolean Extensions

  • isTrue & isFalse - Checks if the Boolean values considering null safety.
  • val - Returns the Boolean value or false if it is null.
  • binary - Returns 1 if the Boolean is true and zero if it is false or null.
  • binaryText - Returns '1' if the Boolean is true and '0' if it is false or null.

DateTime Extensions

  • format & tryFormat - format a DateTime object as a string using a specified format (e.g. "yyyy-MM-dd"), while tryFormat attempts to do the same but returns null if unsuccessful.
  • tryToDateTime - Safely attempts to convert a string to a DateTime object. Returns null if the conversion fails.
  • toDateTime - Converts a string to a DateTime object. Throw an exception if the conversion fails.
  • dateFormat - Returns a DateFormat object based on the string format provided.
  • toDateWithFormat - Converts a string to a DateTime object using a specific format.
  • tryToDateWithFormat - Safely attempts to convert a string to a DateTime object using a specific format. Returns null if the conversion fails.
  • timestampToDate - Converts a timestamp string to a DateTime object.
  • toSmallMonthName & toFullMonthName - Convert an integer representing a month to its abbreviated name.
  • toSmallDayName & toFullDayName - Convert an integer representing a day of the week to its abbreviated name.
  • View All DateTime Extensions

Duration Extensions

  • delayed - Utility to delay some code execution.
  • fromNow - Adds the Duration to the current DateTime and gives a future time.
  • ago - Subtracts the Duration from the current DateTime and gives a pastime.

UI & Design

Color Extensions

  • toHex - Converts a Color object to its hex string representation.
  • toColor - Converts a hex color string to a Color object.
  • isHexColor - Checks if the given string is a valid hexadecimal color string.

Flutter Extensions

ThemeExtensions

  • themeData - Quickly get the current ThemeData from the nearest Theme widget ancestor.
  • txtTheme - Effortlessly obtain the TextTheme for your context.
  • brightness - Determine the brightness setting of the app theme.
  • sysBrightness - Determine the brightness setting of the system.
  • isDark & isLight - Convenient boolean to quickly check if the current theme is light or dark.

MediaQueryExtensions

FocusScopeExtensions

Exceptions

The ConvertObject class throws a ParsingException if there is an error while converting an object. This exception provides information about the type of the object and the method used for conversion.

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.

Buy Me A Coffee