fix search filter tabs and checkbox no data selection

This commit is contained in:
ashrafzarkanisala
2024-09-08 21:02:48 +03:00
parent ce861efa3f
commit e0f7c7ab39
5 changed files with 85 additions and 30 deletions

View File

@ -22,7 +22,7 @@ class DynamicTable extends StatefulWidget {
required this.headers,
required this.data,
required this.size,
this.tableName,
this.tableName,
required this.isEmpty,
required this.withCheckBox,
required this.withSelectAll,
@ -57,13 +57,19 @@ class _DynamicTableState extends State<DynamicTable> {
}
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(deviceUuid);
});
if (widget.data.isEmpty) {
_selected = [];
_selectAll = false;
} else {
_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(deviceUuid);
});
_selectAll = _selected.every((element) => element == true);
}
}
void _toggleRowSelection(int index) {
@ -76,7 +82,6 @@ class _DynamicTableState extends State<DynamicTable> {
});
}
void _toggleSelectAll(bool? value) {
setState(() {
_selectAll = value ?? false;
@ -125,7 +130,9 @@ class _DynamicTableState extends State<DynamicTable> {
),
Text(
// no password
widget.tableName=='AccessManagement'? 'No Password ' : 'No Devices',
widget.tableName == 'AccessManagement'
? 'No Password '
: 'No Devices',
style: Theme.of(context)
.textTheme
.bodySmall!
@ -178,8 +185,11 @@ class _DynamicTableState extends State<DynamicTable> {
),
),
child: Checkbox(
value: _selected.every((element) => element == true),
onChanged:widget.withSelectAll?_toggleSelectAll:null,
value: widget.data.isNotEmpty &&
_selected.every((element) => element == true),
onChanged: widget.withSelectAll && widget.data.isNotEmpty
? _toggleSelectAll
: null,
),
);
}