silahkan buat file reuseableTable.dart lalu salin codingan di bawah
import 'package:flutter/material.dart';
class DataTablePage extends StatelessWidget {
final List<DataColumn> stickyColumns;
final List<DataColumn> columns;
final List<DataRow> stickyRows;
final List<DataRow> rows;
const DataTablePage({
Key? key,
required this.stickyColumns,
required this.columns,
required this.stickyRows,
required this.rows,
}) : super(key: key);
@override
Widget build(BuildContext context) {
// Set a constant color for heading rows
final headingRowColor = MaterialStateProperty.all(Colors.green);
return Row(
children: [
DataTable(
headingRowColor: headingRowColor,
columns: stickyColumns,
rows: stickyRows,
),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
headingRowColor: headingRowColor,
columns: columns,
rows: rows,
),
),
),
],
);
}
}
Berikut contoh pemanggilannya/pemakaian
DataTablePage(
stickyColumns
: const [
DataColumn(
label
: Text('Sticky'),
),
],
stickyRows
: List.generate(
10,
(
index
) {
return DataRow(
cells
: [
DataCell(
Text('Sticky $
index
'),
),
],
);
},
),
columns
: List.generate(
8,
(
index
) {
return DataColumn(
label
: Text('header $
index
'),
);
},
),
rows
: List.generate(10, (
index
) {
return DataRow(
cells
: [
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
DataCell(
Text('data$
index
'),
),
]);
}),
),