FespTableData constructor

FespTableData({
  1. dynamic emptyCell = '-',
  2. double? rowHeightByIndex(
    1. int index
    )?,
  3. double? colWidthByIndex(
    1. int index
    )?,
  4. Size gap = const Size(0, 0),
  5. List<List>? rows,
  6. Map<Object, Map<Object, Object>>? fromDict,
  7. dynamic firstCell = '-',
  8. required Widget builder(
    1. dynamic item,
    2. int x,
    3. int y
    ),
})

Implementation

FespTableData({
  this.emptyCell = '-',
  this.rowHeightByIndex,
  this.colWidthByIndex,
  this.gap = const Size(0, 0),
  this.rows,
  this.fromDict,
  this.firstCell = '-',
  required this.builder,
}) : assert((rows == null || fromDict == null),
          'One of them rows || fromDict must be != null') {
  if (fromDict == null) {
    verticalMaxCount = rows!.length;

    int maxCount = 0;
    for (var e in rows!) {
      if (e.length > maxCount) maxCount = e.length;
    }
    horizontalMaxCount = maxCount;
  } else {
    rows = [];
    final List<Object> verticalHeaders = fromDict!.entries
        .map(
          (e) => e.key,
        )
        .toList();
    final Set<Object> horizontalHeaders = {};

    final entries = fromDict!.entries;

    int maxCount = 0;
    for (var e in entries) {
      if (e.value.length > maxCount) maxCount = e.value.length;
      horizontalHeaders.addAll(e.value.keys);
    }
    verticalMaxCount = entries.length + 1;
    horizontalMaxCount = maxCount + 1;

    final horizontalHeadersList = horizontalHeaders.toList();
    rows!.addAll([
      [firstCell, ...horizontalHeadersList]
    ]);

    for (var v in verticalHeaders) {
      final List<dynamic> row = [];

      final dict = fromDict!;
      for (var i = 0; i < horizontalHeadersList.length; i++) {
        final h = horizontalHeadersList[i];
        if (dict[v]!.containsKey(h)) {
          row.add(dict[v]![h]!);
        } else {
          row.add(null);
        }
      }
      rows!.add([v, ...row]);
    }
  }
}