Merged with dev and solved conflicts

This commit is contained in:
Abdullah Alassaf
2024-09-03 12:18:17 +03:00
19 changed files with 277 additions and 182 deletions

View File

@ -16,6 +16,7 @@ class DynamicTable extends StatefulWidget {
final void Function(bool?)? selectAll;
final void Function(int, bool, dynamic)? onRowSelected;
final List<String>? initialSelectedIds;
final int uuidIndex;
const DynamicTable({
super.key,
required this.headers,
@ -30,6 +31,7 @@ class DynamicTable extends StatefulWidget {
this.selectAll,
this.onRowSelected,
this.initialSelectedIds,
required this.uuidIndex,
});
@override
@ -43,9 +45,24 @@ class _DynamicTableState extends State<DynamicTable> {
@override
void initState() {
super.initState();
_initializeSelection();
}
@override
void didUpdateWidget(DynamicTable oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.data != widget.data) {
_initializeSelection();
}
}
void _initializeSelection() {
_selected = List<bool>.generate(widget.data.length, (index) {
// Check if the initialSelectedIds contains the deviceUuid
// uuidIndex is the index of the column containing the deviceUuid
final deviceUuid = widget.data[index][widget.uuidIndex];
return widget.initialSelectedIds != null &&
widget.initialSelectedIds!.contains(widget.data[index][1]);
widget.initialSelectedIds!.contains(deviceUuid);
});
}
@ -87,8 +104,7 @@ class _DynamicTableState extends State<DynamicTable> {
children: [
if (widget.withCheckBox) _buildSelectAllCheckbox(),
...widget.headers
.map((header) => _buildTableHeaderCell(header))
.toList(),
.map((header) => _buildTableHeaderCell(header)),
],
),
),
@ -136,11 +152,9 @@ class _DynamicTableState extends State<DynamicTable> {
if (widget.withCheckBox)
_buildRowCheckbox(
index, widget.size.height * 0.10),
...row
.map((cell) => _buildTableCell(
cell.toString(),
widget.size.height * 0.10))
.toList(),
...row.map((cell) => _buildTableCell(
cell.toString(),
widget.size.height * 0.10)),
],
);
},