mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
push living room status
This commit is contained in:
@ -12,7 +12,7 @@ class DynamicTable extends StatefulWidget {
|
||||
final bool withCheckBox;
|
||||
final bool isEmpty;
|
||||
final void Function(bool?)? selectAll;
|
||||
final void Function(int, bool?)? onRowCheckboxChanged;
|
||||
final void Function(int, bool, dynamic)? onRowSelected;
|
||||
final List<String>? initialSelectedIds;
|
||||
|
||||
const DynamicTable({
|
||||
@ -25,7 +25,7 @@ class DynamicTable extends StatefulWidget {
|
||||
this.headerDecoration,
|
||||
this.cellDecoration,
|
||||
this.selectAll,
|
||||
this.onRowCheckboxChanged,
|
||||
this.onRowSelected,
|
||||
this.initialSelectedIds,
|
||||
});
|
||||
|
||||
@ -35,7 +35,6 @@ class DynamicTable extends StatefulWidget {
|
||||
|
||||
class _DynamicTableState extends State<DynamicTable> {
|
||||
late List<bool> _selected;
|
||||
bool _selectAll = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -44,25 +43,19 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
return widget.initialSelectedIds != null &&
|
||||
widget.initialSelectedIds!.contains(widget.data[index][1]);
|
||||
});
|
||||
_selectAll = _selected.every((element) => element == true);
|
||||
}
|
||||
|
||||
void _toggleSelectAll(bool? value) {
|
||||
void _toggleRowSelection(int index) {
|
||||
setState(() {
|
||||
_selectAll = value ?? false;
|
||||
_selected = List<bool>.filled(widget.data.length, _selectAll);
|
||||
if (widget.selectAll != null) {
|
||||
widget.selectAll!(_selectAll);
|
||||
// Deselect all rows
|
||||
for (int i = 0; i < _selected.length; i++) {
|
||||
_selected[i] = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Select the clicked row
|
||||
_selected[index] = true;
|
||||
|
||||
void _toggleRowSelection(int index, bool? value) {
|
||||
setState(() {
|
||||
_selected[index] = value ?? false;
|
||||
_selectAll = _selected.every((element) => element == true);
|
||||
if (widget.onRowCheckboxChanged != null) {
|
||||
widget.onRowCheckboxChanged!(index, _selected[index]);
|
||||
if (widget.onRowSelected != null) {
|
||||
widget.onRowSelected!(index, true, widget.data[index]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -108,7 +101,7 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
height: 15,
|
||||
),
|
||||
Text(
|
||||
'No Passwords',
|
||||
'No Devices',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
@ -157,81 +150,104 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
|
||||
Widget _buildSelectAllCheckbox() {
|
||||
return Container(
|
||||
width: 50, // Fixed width to align with the checkbox column
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: ColorsManager.boxDivider))),
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: ColorsManager.boxDivider),
|
||||
),
|
||||
),
|
||||
child: Checkbox(
|
||||
value: _selectAll,
|
||||
onChanged: _toggleSelectAll,
|
||||
value: _selected.every((element) => element == true),
|
||||
onChanged: null, // Disabling the toggle as we're not using select all
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRowCheckbox(int index, size) {
|
||||
Widget _buildRowCheckbox(int index, double size) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
height: size,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
width: 50, // Fixed width to align with the checkbox column
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
height: size,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorsManager.boxDivider,
|
||||
width: 1.0,
|
||||
),
|
||||
)),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Center(
|
||||
child: Checkbox(
|
||||
value: _selected[index],
|
||||
onChanged: (bool? value) {
|
||||
_toggleRowSelection(index, value);
|
||||
},
|
||||
),
|
||||
));
|
||||
),
|
||||
),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Center(
|
||||
child: Checkbox(
|
||||
value: _selected[index],
|
||||
onChanged: (bool? value) {
|
||||
_toggleRowSelection(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTableHeaderCell(String title) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: ColorsManager.boxDivider))),
|
||||
border: Border.symmetric(
|
||||
vertical: BorderSide(color: ColorsManager.boxDivider),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999))),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 13,
|
||||
color: Color(0xFF999999),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTableCell(String content, size) {
|
||||
Widget _buildTableCell(String content, double size) {
|
||||
// Check if the content is a battery level percentage
|
||||
bool isBatteryLevel = content.endsWith('%');
|
||||
double? batteryLevel;
|
||||
|
||||
if (isBatteryLevel) {
|
||||
batteryLevel = double.tryParse(content.replaceAll('%', '').trim());
|
||||
}
|
||||
|
||||
return Expanded(
|
||||
child: Container(
|
||||
height: size,
|
||||
padding: const EdgeInsets.all(5.0),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorsManager.boxDivider,
|
||||
width: 1.0,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: ColorsManager.boxDivider,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
content,
|
||||
style: TextStyle(
|
||||
color: content == 'Online'
|
||||
? ColorsManager.green
|
||||
: content == 'Offline'
|
||||
? ColorsManager.red
|
||||
: Colors.black,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400),
|
||||
color: batteryLevel != null && batteryLevel < 20
|
||||
? ColorsManager.red // Red color for low battery
|
||||
: content == 'Online'
|
||||
? ColorsManager.green // Green color for Online
|
||||
: content == 'Offline'
|
||||
? ColorsManager.red // Red color for Offline
|
||||
: Colors.black,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user