44 lines
956 B
Dart
44 lines
956 B
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
abstract class DataTableContent {
|
||
|
bool selected = false;
|
||
|
List<DataCell> asDataTableCells(List<Widget> actions) => [];
|
||
|
static List<DataColumn> asDataTableColumns() => [];
|
||
|
}
|
||
|
|
||
|
class DataTableSourceBuilder extends DataTableSource {
|
||
|
final List<DataTableContent> data;
|
||
|
final BuildContext context;
|
||
|
|
||
|
DataTableSourceBuilder(this.context, this.data);
|
||
|
|
||
|
@override
|
||
|
bool get isRowCountApproximate => false;
|
||
|
|
||
|
@override
|
||
|
int get rowCount => data.length;
|
||
|
|
||
|
@override
|
||
|
int get selectedRowCount {
|
||
|
int count = 0;
|
||
|
for (var element in data) {
|
||
|
if (element.selected) {
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
DataRow? getRow(int index) {
|
||
|
assert(index >= 0);
|
||
|
if (index >= data.length) return null;
|
||
|
final rowData = data[index];
|
||
|
return DataRow.byIndex(
|
||
|
index: index,
|
||
|
selected: rowData.selected,
|
||
|
cells: rowData.asDataTableCells([]),
|
||
|
);
|
||
|
}
|
||
|
}
|