compareEntityIDs function

int compareEntityIDs(
  1. Object? id1,
  2. Object? id2
)

Compares 2 entity IDs, implementing the orderByID ordering of the select* methods.

Implementation

int compareEntityIDs(Object? id1, Object? id2) {
  if (identical(id1, id2)) return 0;

  if (id1 == null) return id2 == null ? 0 : 1;
  if (id2 == null) return -1;

  if (id1 is num && id2 is num) return id1.compareTo(id2);
  if (id1 is String && id2 is String) return id1.compareTo(id2);

  if (id1 is Comparable && id2 is Comparable) {
    if (id1.runtimeType == id2.runtimeType) {
      return id1.compareTo(id2);
    }
  }

  return 0;
}