buildRow method

DataRow buildRow({
  1. required Map<String, dynamic> objectAsJson,
  2. required FieldPressedCallback onFieldPressed,
  3. required int cellsNumber,
  4. required int objectIndex,
  5. required void onSelectRow({
    1. required int index,
    2. required bool selected,
    }),
  6. required bool isSelected,
  7. required bool enableSelection,
  8. required List<String> keys,
})

Implementation

DataRow buildRow({
  required Map<String, dynamic> objectAsJson,
  required FieldPressedCallback onFieldPressed,
  required int cellsNumber,
  required int objectIndex,
  required void Function({
    required bool selected,
    required int index,
  })
      onSelectRow,
  required bool isSelected,
  required bool enableSelection,
  required List<String> keys,
}) {
  String dataCellValue(
    dynamic field,
  ) {
    if (field.runtimeType == List<Map<String, dynamic>>) {
      return 'List OF Objects';
    } else if (isMap(field)) {
      return "Object";
    } else if (isList(field)) {
      return 'List';
    } else {
      return field.toString();
    }
  }

  List<String> rowKeys = [];
  rowKeys = keys;

  return DataRow(
    onSelectChanged: !enableSelection
        ? null
        : (isSelected) =>
            onSelectRow(selected: isSelected!, index: objectIndex),
    selected: isSelected,
    cells: rowKeys.map<DataCell>((fieldName) {
      final cellValue = dataCellValue(objectAsJson[fieldName]);
      final isList = cellValue == 'List';
      return DataCell(
        onLongPress: () {
          final value = objectAsJson[fieldName];
          final json = const JsonEncoder.withIndent('  ').convert(value);
          FlutterClipboardHiveUi.copy(json);
        },
        Center(
          child: Text(
            cellValue,
          ),
        ),
        onTap: () => !isList
            ? onFieldPressed(
                "boxName",
                fieldName,
                objectAsJson,
                objectIndex: objectIndex,
              )
            : showListDetailsDialog(
                fieldName,
                objectAsJson[fieldName] as List,
              ),
      );
    }).toList(),
  );
}