after method

bool? after(
  1. T object1,
  2. T object2
)

is object1 listed after object2?

Implementation

bool? after(T object1, T object2) {
  List<String> fields = <String>[];

  if (_query.limiters.containsKey('order')) {
    fields = _query.limiters['order'].toString().split(',');
  }
  fields.add(keyVarCreatedAt);
  for (String key in fields) {
    bool reverse = false;
    if (key.startsWith('-')) {
      reverse = true;
      key = key.substring(1);
    }
    final dynamic val1 = object1.get<dynamic>(key);
    final dynamic val2 = object2.get<dynamic>(key);

    if (val1 == null && val2 == null) {
      break;
    }
    if (val1 == null) {
      return reverse;
    }
    if (val2 == null) {
      return !reverse;
    }

    if (val1 is num && val2 is num) {
      if (val1 < val2) {
        return reverse;
      }
      if (val1 > val2) {
        return !reverse;
      }
    } else if (val1 is String && val2 is String) {
      if (val1.toString().compareTo(val2) < 0) {
        return reverse;
      }
      if (val1.toString().compareTo(val2) > 0) {
        return !reverse;
      }
    } else if (val1 is DateTime && val2 is DateTime) {
      if (val1.isAfter(val2)) {
        return !reverse;
      }
      if (val1.isBefore(val2)) {
        return reverse;
      }
    }
  }
  return null;
}