buildDataTable function
Implementation
Widget buildDataTable({
required String id,
required Map<String, dynamic> props,
}) {
final columns = mapsOf(props['columns']);
final rows = mapsOf(props['rows']);
if (columns.isEmpty) {
return Text(
props['emptyMessage']?.toString() ?? '',
key: ValueKey(id),
);
}
return SingleChildScrollView(
key: ValueKey(id),
scrollDirection: Axis.horizontal,
child: DataTable(
columns: [
for (final column in columns)
DataColumn(
label: Text(
column['label']?.toString() ?? column['key']?.toString() ?? '',
),
),
],
rows: [
for (final row in rows)
DataRow(
cells: [
for (final column in columns)
DataCell(Text('${row[column['key']] ?? ''}')),
],
),
],
),
);
}