compare static method

int? compare(
  1. dynamic a,
  2. dynamic b, {
  3. bool ascending = true,
  4. bool ignoreCase = true,
})

compareTo function with ascending/descending and ignore case

Implementation

static int? compare(dynamic a, dynamic b,
    {bool ascending = true, bool ignoreCase = true}) {
  if ((a == null) && (b == null)) return 0;
  if ((a == null) && (b != null)) return (ascending == true) ? -1 : 1;
  if ((a != null) && (b == null)) return (ascending == true) ? 1 : -1;

  if ((a is String) && (ignoreCase == true)) a = a.toLowerCase();
  if ((b is String) && (ignoreCase == true)) b = b.toLowerCase();
  if (ascending == true) {
    return a.compareTo(b);
  } else {
    return b.compareTo(a);
  }
}