Fixed design issues

This commit is contained in:
Abdullah Alassaf
2024-10-08 01:56:09 +03:00
parent d05328e998
commit 813f2f2693
7 changed files with 114 additions and 98 deletions

View File

@ -53,11 +53,26 @@ class _DynamicTableState extends State<DynamicTable> {
@override
void didUpdateWidget(DynamicTable oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.data.length != widget.data.length) {
if (!_compareListOfLists(oldWidget.data, widget.data)) {
_initializeSelection();
}
}
bool _compareListOfLists(List<List<dynamic>> oldList, List<List<dynamic>> newList) {
// Check if the old and new lists are the same
if (oldList.length != newList.length) return false;
for (int i = 0; i < oldList.length; i++) {
if (oldList[i].length != newList[i].length) return false;
for (int j = 0; j < oldList[i].length; j++) {
if (oldList[i][j] != newList[i][j]) return false;
}
}
return true;
}
void _initializeSelection() {
_selectedRows = List<bool>.filled(widget.data.length, false);
_selectAll = false;
@ -90,13 +105,11 @@ class _DynamicTableState extends State<DynamicTable> {
child: Column(
children: [
Container(
decoration: widget.headerDecoration ??
BoxDecoration(color: Colors.grey[200]),
decoration: widget.headerDecoration ?? BoxDecoration(color: Colors.grey[200]),
child: Row(
children: [
if (widget.withCheckBox) _buildSelectAllCheckbox(),
...widget.headers
.map((header) => _buildTableHeaderCell(header)),
...widget.headers.map((header) => _buildTableHeaderCell(header)),
],
),
),
@ -123,8 +136,7 @@ class _DynamicTableState extends State<DynamicTable> {
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor),
.copyWith(color: ColorsManager.grayColor),
)
],
),
@ -144,11 +156,9 @@ class _DynamicTableState extends State<DynamicTable> {
return Row(
children: [
if (widget.withCheckBox)
_buildRowCheckbox(
index, widget.size.height * 0.10),
...row.map((cell) => _buildTableCell(
cell.toString(),
widget.size.height * 0.10)),
_buildRowCheckbox(index, widget.size.height * 0.10),
...row.map((cell) =>
_buildTableCell(cell.toString(), widget.size.height * 0.10)),
],
);
},
@ -173,9 +183,7 @@ class _DynamicTableState extends State<DynamicTable> {
),
child: Checkbox(
value: _selectAll,
onChanged: widget.withSelectAll && widget.data.isNotEmpty
? _toggleSelectAll
: null,
onChanged: widget.withSelectAll && widget.data.isNotEmpty ? _toggleSelectAll : null,
),
);
}