validateHomogeneousType function

void validateHomogeneousType(
  1. List list, {
  2. String message = 'Inconsistent data types in list.',
})

Validates that all elements in the list are of the same runtimeType.

Implementation

void validateHomogeneousType(List<dynamic> list, {String message = 'Inconsistent data types in list.'}) {
  if (list.isEmpty) return;

  final type = list.first.runtimeType;
  if (list.any((e) => e.runtimeType != type)) {
    throw ArgumentError(message);
  }
}