dart_ext 1.0.0

  • Readme
  • Changelog
  • Installing
  • 12

#dart_ext A set of useful helper functions


###1. Depend on it Add this to your package's pubspec.yaml file:

    dart_ext: any

###2. Install it

  run pub get in Dart Editor or form command line

###3. Import it Add this line in your dart code:

  import 'package:dart_ext/dart_ext.dart';


###Object ####dynamic clone(dynamic source) return a clone of the specified object

###Function ####relaxFn(Function function) An funtion wrapper which support flexable number of arguments

####bind(Function functoin, List args) Partially apply a function by filling in 0 to 5 number of its arguments;

  • function - The function with partially filled args
  • args - A List of prefilled args.


    Function add = (num a, num b) { return a + b; };
    var add5 = new bind(add, [5]);
    num rt = add5(6);

####invokeMethod(var target, String methodName, [arg0, arg1, arg2, arg3, arg4, arg5]) Invoke the given method in the target object.

  • target - the object where the mehtod invoked from
  • 'methodName` - the function name
  • [arg0, arg1, arg2, arg3, arg4, arg5] - optional arguments. Suport 0 to 6 args. Exception: if the method didn't exist in the target object, it throws

###String ####String capitalize(String s) return a capitalized string

###Map ####dynamic getValue(Map source, dynamic key, [defaultValue = null]) return the value of given key in the map. If the key didn't exit, return given defaultValue or null if defaultValue didn't represent.

  • source - the map to get value from
  • key - the key of the value to get
  • defaultValue - the defaultValue to return if the key didn't exist in the map. defaultValue can be a function.


    Map m = {
      'one': 1,
      'two': 2
    num two = getValue(m, 'two');       //  two = 2
    num zero = getValue(m, 'zero');     //  zero = null
    zero = getValue(m, 'zero', 0);      //  zero = 0
    num four = getValue(m, 'three', (){ return getValue(m, 'three', 3) + 1; });  // four = 4

####void setValue(Map source, dynamic key, dynamic value) Add key/value to the given map. Equivalent to source[key] = value. It is convenient to use in a setter which set a value in map.

  Map _config = {};
  void set name(String value) => setValue(_config, 'name', value);

####Map merge(Map map1, others, {Function iterableMergeFunc}) Merge maps into a new map.

  • others - can be a Map or a list
  • iterableMergeFunc - a custom merge function to override default iterable merge behavior
  import 'package:dart_ext/collection_ext.dart';  // only import collection extension
  Map one = {
    'a': 'a',
    'b': 'b',
    'list': [{ 'one': 1 }, { 'two': 2 }]
  Map two = {
    'a': 'A'
    'b': 3,
    'list': [{ 'two': 2 }, { 'three': 3 }, 4 ]
  Map three = {
    'a': 'A',
    'b': 4,
    'list': [{ 'three': 3 }, { 'four': 4}, 5, 6]
  Map merged = merge(one, two);
  // merged is:
    'a': 'A',
    'b': 3,
    'list': [{'one': 1, 'two': 2}, {'two': 2, 'three': 3}, 4]
  merged = merge(one, [two, three]);
  // merged is:
    'a': 'A',
    'b': 4,
    'list': [{'one': 1, 'two': 2, 'three': 3}, {'two': 2, 'three': 3, 'four': 4}, 5, 6]
  merged = merge(one, two, (target, other) {
    list<num> toReturn = [];
    void _merge(List l) {
        target.forEach((t) {
            if (t is Map) {
                t.forEach((k, v) {
                    if (toReturn.contains(v) == false) {
            } else if (toReturn.contains(v) == false) {
    return toReturn;
  // merged is:
    'a': 'A',
    'b': 3,
    'list': [1, 2, 3, 4]


  1. merge didn't check value type.
  2. if the value was a Iterable, it merge items at the same index.


  • Remove mirror from function_ext.dart
  • Removed dart_ext.dart file


  • Separate invoke method into function_ext_mirror_invoke.dart;


  • fixed an issue where null value in map was treated not exist.


  • Suport merge unlimieted number of Map
  • Add ability to override default Iterable merge behavior


  • Add @MirrorUsed annotation


  • Changed partial to bind
  • Added getMethod and invokeMethod in function_ext.

#v0.0.5 Features:

  • Add relaxFn - a function with flexible arguments
  • Add partial - a fuction callback with partially filled arguments.

Use this package as a library

1. Depend on it

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

  dart_ext: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:dart_ext/collection_ext.dart';
import 'package:dart_ext/function_ext.dart';
import 'package:dart_ext/function_ext_mirror_invoke.dart';
import 'package:dart_ext/string_ext.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21


Detected platforms:

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.5.1.
 Because dart_ext requires SDK version >=1.24.0 <2.0.1, version solving failed.

Health suggestions

Format lib/collection_ext.dart.

Run dartfmt to format lib/collection_ext.dart.

Format lib/function_ext.dart.

Run dartfmt to format lib/function_ext.dart.

Format lib/function_ext_mirror_invoke.dart.

Run dartfmt to format lib/function_ext_mirror_invoke.dart.

Format lib/string_ext.dart.

Run dartfmt to format lib/string_ext.dart.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Support future stable Dart 2 SDKs in pubspec.yaml. (-20 points)

The SDK constraint in pubspec.yaml doesn't allow future stable Dart 2.x SDK releases.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Package is getting outdated. (-62.47 points)

The package was last published 84 weeks ago.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and dart_ext.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.1