utils_extensions 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

UtilsExtension #

Flutter commonly used utility/helper with implanted function inside data types (Extension), like kotlin & swift extension.

Getting Started #

In your flutter project add the dependency:

dependencies:
  ...
  utils_extensions: ^0.1.1

Importing package

import 'package:utils_extensions/utils_extensions.dart';

Utils & Extension Contents #

Extension - String #

// Validator
bool isNull();
bool isNullOrBlank();
bool isNum(String s); // True if string is num (int or double)
bool isNumericOnly(String s); // True if string is only have numeric value 
bool isAlphabetOnly(String s);
bool isBool();
bool isVector();
bool isImage(); 
bool isAudio(); 
bool isVideo(); 
bool isTxt(); 
bool isDocument(); 
bool isExcel();
bool isPPT(); 
bool isApk(); 
bool isPDF(); 
bool isHTML();
bool isURL();
bool isDateTime();
bool isEmail({int minLength, int maxLength});
bool isPhoneNumber({int minLength, int maxLength});
bool isHexadecimal();
bool isMD5();
bool isSHA1();
bool isSHA256();
bool isISBN();
bool isSSN();
bool isPassport();
bool isGithubRepo();
bool isBinary();
bool isPalindrom();
bool isOneAKind();
bool isCurrency();
bool isIPv4();
bool isIPv6();
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int minLength, int maxLength);
bool isCaseInsensitiveContains(String compareTo);
bool isCaseInsensitiveContainsAny(String compareTo);
bool isCamelCase();
bool isCapitalize({bool firstOnly = false});

// Exception
Exception toException();
Exception toFormatException([dynamic source]);

// Parser
int toInt({bool nullOnError = false});
double toDouble({bool nullOnError = false});
num toNum({bool nullOnError = false});
bool toBool({bool falseOnError = false});
DateTime toDateTime();
String toBinary({bool nullOnError = false});
int toIntFromBinary({bool nullOnError = false});
String toSSN({bool nullOnError = false});
String toCapitalize({bool firstOnly = false});
String toCamelCase();
String toNumericOnly();

// Widget
Text toText({
    Key key,
    TextStyle style,
    StrutStyle strutStyle,
    TextAlign textAlign,
    TextDirection textDirection,
    Locale locale,
    bool softWrap,
    TextOverflow overflow,
    double textScaleFactor,
    int maxLines,
    String semanticsLabel,
    TextWidthBasis textWidthBasis,
  });
Center toTextCentered({
  Key key,
  TextStyle style,
  StrutStyle strutStyle,
  TextDirection textDirection,
  Locale locale,
  bool softWrap,
  TextOverflow overflow,
  double textScaleFactor,
  int maxLines,
  String semanticsLabel,
  TextWidthBasis textWidthBasis,
});

Extension - num #

this extension can also be used from int and double data types

// Validator
bool isNull();
bool isNullOrBlank();
bool isLowerThan(num compareTo);
bool isGreaterThan(num compareTo);
bool isEqualTo(num compareTo);
bool isPhoneNumber({int minLength, int maxLength});
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int maxLength);

// Widget
Text toText({
    Key key,
    TextStyle style,
    StrutStyle strutStyle,
    TextAlign textAlign,
    TextDirection textDirection,
    Locale locale,
    bool softWrap,
    TextOverflow overflow,
    double textScaleFactor,
    int maxLines,
    String semanticsLabel,
    TextWidthBasis textWidthBasis,
  });
Center toTextCentered({
  Key key,
  TextStyle style,
  StrutStyle strutStyle,
  TextDirection textDirection,
  Locale locale,
  bool softWrap,
  TextOverflow overflow,
  double textScaleFactor,
  int maxLines,
  String semanticsLabel,
  TextWidthBasis textWidthBasis,
});

Extension - int #

int data type can also use extension from num

// Validator
bool isPalindrom();
bool isBinary();
bool isOneAKind();

// Parse
String toBinary();
String toBinaryInt();
String fromBinary();
DateTime toDateTime({bool isMicroSeconds});
String toSSN({bool nullOnError = false});
String toISBN({bool nullOnError = false});

Extension - List #

// Validator
bool isNull();
bool isNullOrBlank();
bool isBinary();
bool isOneAKind();
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int maxLength);

// Parse
String toJsonString();
num valueTotal(); // Only accepting num, int, double data type

Extension - Map #

// Validator
bool isNull();
bool isNullOrBlank();
bool isBinary();
bool isOneAKind();
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int maxLength);

// Parse
String toJsonString();

Extension - Set #

// Validator
bool isNull();
bool isNullOrBlank();
bool isBinary();
bool isOneAKind();
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int maxLength);

// Parse
String toJsonString();
num valueTotal(); // Only accepting num, int, double data type

Utils - enum_util #

String enumValue(Object o); // Return string value of enum

Utils - TransformUtil #

String toBinary(int i);
String toBinaryInt(int i);
int fromBinary(String binaryStr);
String capitalize(String s, {bool firstOnly = false});
String capitalizeFirst(String s); // Capitalize only the first word
String removeAllWhitespace(String s);
String camelCase(String s);
String numericOnly(String s, {bool firstWordOnly = false});
String toSSN(String s);

Utils - ValidatorUtil #

bool isNull(dynamic s);
bool isNullOrBlank(dynamic s);
bool isNum(String s); // True if string is num (int or double)
bool isNumericOnly(String s); // True if string is only have numeric value 
bool isAlphabetOnly(String s);
bool isBool(String s);
bool isVector(String s);
bool isImage(String s); 
bool isAudio(String s); 
bool isVideo(String s); 
bool isTxt(String s); 
bool isDocument(String s); 
bool isExcel(String s);
bool isPPT(String s); 
bool isApk(String s); 
bool isPDF(String s); 
bool isHTML(String s);
bool isURL(String s);
bool isDateTime(String s);
bool isEmail({int minLength, int maxLength});
bool isPhoneNumber({int minLength, int maxLength});
bool isHexadecimal(String s);
bool isMD5(String s);
bool isSHA1(String s);
bool isSHA256(String s);
bool isISBN(String s);
bool isSSN(String s);
bool isPassport(String s);
bool isGithubRepo(String s);
bool isBinary(String s);
bool isPalindrom(String s);
bool isOneAKind(dynamic s);
bool isCurrency(String s);
bool isIPv4(String s);
bool isIPv6(String s);
bool isLengthLowerThan(int maxLength);
bool isLengthLowerOrEqual(int maxLength);
bool isLengthGreaterThan(int maxLength);
bool isLengthGreaterOrEqual(int maxLength);
bool isLengthEqualTo(int maxLength);
bool isLengthBetween(int minLength, int maxLength);
bool isCaseInsensitiveContains(String compareTo);
bool isCaseInsensitiveContainsAny(String compareTo);
bool isLowerThan(num compareTo);
bool isGreaterThan(num compareTo);
bool isEqualTo(num compareTo);
bool isCamelCase(String s);
bool isCapitalize(String s, {bool firstOnly = false});

[0.1.1] - 05/02/2020 #

  • Fix isNull method.

[0.1.0] - 04/29/2020 #

  • Initial Release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:utils_extensions/utils_extensions.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Utils Extensions Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Utils Extensions Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Example transform string to text widget
        title: widget.title.toText(),
      ),
      // Example transform string to centered text widget
      body:
          'This text is using toTextCentered function from utils_extensions plugin'
              .toTextCentered(style: TextStyle(color: Colors.blue)),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  utils_extensions: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:utils_extensions/utils_extensions.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
45
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [utils_extensions] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
regexpattern ^0.2.3 0.2.3
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test