isListOfListValuesAllEquals function
Returns true if the values of the sub-lists of list are all equals
to eqValue.
- With
eqValueIndex: compares only the value at indexeqValueIndexof each sub-list.eqValuedefaults to the value ateqValueIndexof the first sub-list. - Without
eqValueIndex: compares every value of every sub-list (empty sub-lists have no values to compare).eqValuedefaults to the first value of the first non-empty sub-list. If all the sub-lists are empty, returnsfalse.
Implementation
bool isListOfListValuesAllEquals(
Iterable<List>? list, {
Object? eqValue,
int? eqValueIndex,
}) {
if (list == null) return false;
if (list.isEmpty) return false;
if (eqValueIndex != null) {
eqValue ??= list.first[eqValueIndex];
return listMatchesAll(list, (v) => v[eqValueIndex] == eqValue);
}
var hasValues = false;
for (var l in list) {
for (var v in l) {
if (!hasValues) {
hasValues = true;
eqValue ??= v;
}
if (v != eqValue) return false;
}
}
return hasValues;
}