columnMaxLengths function

List<int> columnMaxLengths (
  1. List<List<Object>> data
)

Implementation

List<int> columnMaxLengths(List<List<Object>> data) {
  if (data == null || data.isEmpty) {
    return [];
  }
  final maxColumnLengths = List<int>(data[0].length);
  for (final row in data) {
    final columnCount = row.length;

    for (final column in _range(columnCount)) {
      final itemLength = row[column].toString().length;
      maxColumnLengths[column] = (itemLength > (maxColumnLengths[column] ?? 0))
          ? itemLength
          : maxColumnLengths[column] ?? 0;
    }
  }
  return maxColumnLengths;
}