mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 14:47:23 +00:00
push selectAll bug, design and icons fixes
This commit is contained in:
@ -17,6 +17,7 @@ class DynamicTable extends StatefulWidget {
|
||||
final void Function(int, bool, dynamic)? onRowSelected;
|
||||
final List<String>? initialSelectedIds;
|
||||
final int uuidIndex;
|
||||
final Function(dynamic selectedRows)? onSelectionChanged;
|
||||
const DynamicTable({
|
||||
super.key,
|
||||
required this.headers,
|
||||
@ -32,6 +33,7 @@ class DynamicTable extends StatefulWidget {
|
||||
this.onRowSelected,
|
||||
this.initialSelectedIds,
|
||||
required this.uuidIndex,
|
||||
this.onSelectionChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -39,7 +41,7 @@ class DynamicTable extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DynamicTableState extends State<DynamicTable> {
|
||||
late List<bool> _selected;
|
||||
late List<bool> _selectedRows;
|
||||
bool _selectAll = false;
|
||||
|
||||
@override
|
||||
@ -51,47 +53,30 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
@override
|
||||
void didUpdateWidget(DynamicTable oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.data != widget.data) {
|
||||
if (oldWidget.data.length != widget.data.length) {
|
||||
_initializeSelection();
|
||||
}
|
||||
}
|
||||
|
||||
void _initializeSelection() {
|
||||
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) {
|
||||
setState(() {
|
||||
_selected[index] = !_selected[index];
|
||||
|
||||
if (widget.onRowSelected != null) {
|
||||
widget.onRowSelected!(index, _selected[index], widget.data[index]);
|
||||
}
|
||||
});
|
||||
_selectedRows = List<bool>.filled(widget.data.length, false);
|
||||
_selectAll = false;
|
||||
}
|
||||
|
||||
void _toggleSelectAll(bool? value) {
|
||||
setState(() {
|
||||
_selectAll = value ?? false;
|
||||
_selected = List<bool>.filled(widget.data.length, _selectAll);
|
||||
for (int i = 0; i < widget.data.length; i++) {
|
||||
if (widget.onRowSelected != null) {
|
||||
widget.onRowSelected!(i, _selectAll, widget.data[i]);
|
||||
}
|
||||
}
|
||||
_selectedRows = List<bool>.filled(widget.data.length, _selectAll);
|
||||
});
|
||||
widget.onSelectionChanged?.call(_selectedRows);
|
||||
}
|
||||
|
||||
void _toggleRowSelection(int index) {
|
||||
setState(() {
|
||||
_selectedRows[index] = !_selectedRows[index];
|
||||
_selectAll = _selectedRows.every((isSelected) => isSelected);
|
||||
});
|
||||
widget.onSelectionChanged?.call(_selectedRows);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -211,7 +196,7 @@ class _DynamicTableState extends State<DynamicTable> {
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Center(
|
||||
child: Checkbox(
|
||||
value: _selected[index],
|
||||
value: _selectedRows[index],
|
||||
onChanged: (bool? value) {
|
||||
_toggleRowSelection(index);
|
||||
},
|
||||
|
@ -46,6 +46,7 @@ class AcDeviceBatchControlView extends StatelessWidget
|
||||
),
|
||||
children: [
|
||||
ToggleWidget(
|
||||
icon: Assets.ac,
|
||||
deviceId: devicesIds.first,
|
||||
code: 'switch',
|
||||
value: state.status.acSwitch,
|
||||
|
@ -40,6 +40,7 @@ class BatchFanSpeedControl extends StatelessWidget {
|
||||
value == FanSpeeds.low),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
|
@ -43,7 +43,7 @@ class AcToggle extends StatelessWidget {
|
||||
child: Container(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
icon ?? Assets.acDevice,
|
||||
icon ?? Assets.lightPulp,
|
||||
width: 60,
|
||||
height: 60,
|
||||
fit: BoxFit.cover,
|
||||
|
@ -40,6 +40,7 @@ class FanSpeedControl extends StatelessWidget {
|
||||
value == FanSpeeds.low),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
|
@ -25,6 +25,7 @@ class DeviceManagementBloc
|
||||
on<SelectDevice>(_onSelectDevice);
|
||||
on<ResetFilters>(_onResetFilters);
|
||||
on<ResetSelectedDevices>(_onResetSelectedDevices);
|
||||
on<UpdateSelection>(_onUpdateSelection);
|
||||
}
|
||||
|
||||
Future<void> _onFetchDevices(
|
||||
@ -172,6 +173,48 @@ class DeviceManagementBloc
|
||||
}
|
||||
}
|
||||
|
||||
void _onUpdateSelection(
|
||||
UpdateSelection event, Emitter<DeviceManagementState> emit) {
|
||||
List<AllDevicesModel> selectedDevices = [];
|
||||
List<AllDevicesModel> devicesToSelectFrom = [];
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
|
||||
} else if (state is DeviceManagementFiltered) {
|
||||
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
|
||||
}
|
||||
|
||||
for (int i = 0; i < event.selectedRows.length; i++) {
|
||||
if (event.selectedRows[i]) {
|
||||
selectedDevices.add(devicesToSelectFrom[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
final loadedState = state as DeviceManagementLoaded;
|
||||
emit(DeviceManagementLoaded(
|
||||
devices: loadedState.devices,
|
||||
selectedIndex: loadedState.selectedIndex,
|
||||
onlineCount: loadedState.onlineCount,
|
||||
offlineCount: loadedState.offlineCount,
|
||||
lowBatteryCount: loadedState.lowBatteryCount,
|
||||
selectedDevice: selectedDevices,
|
||||
isControlButtonEnabled: _checkIfControlButtonEnabled(selectedDevices),
|
||||
));
|
||||
} else if (state is DeviceManagementFiltered) {
|
||||
final filteredState = state as DeviceManagementFiltered;
|
||||
emit(DeviceManagementFiltered(
|
||||
filteredDevices: filteredState.filteredDevices,
|
||||
selectedIndex: filteredState.selectedIndex,
|
||||
onlineCount: filteredState.onlineCount,
|
||||
offlineCount: filteredState.offlineCount,
|
||||
lowBatteryCount: filteredState.lowBatteryCount,
|
||||
selectedDevice: selectedDevices,
|
||||
isControlButtonEnabled: _checkIfControlButtonEnabled(selectedDevices),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
bool _checkIfControlButtonEnabled(List<AllDevicesModel> selectedDevices) {
|
||||
if (selectedDevices.length > 1) {
|
||||
final productTypes =
|
||||
|
@ -54,3 +54,9 @@ class SelectDevice extends DeviceManagementEvent {
|
||||
class ResetFilters extends DeviceManagementEvent {}
|
||||
|
||||
class ResetSelectedDevices extends DeviceManagementEvent {}
|
||||
|
||||
class UpdateSelection extends DeviceManagementEvent {
|
||||
final List<bool> selectedRows;
|
||||
|
||||
const UpdateSelection(this.selectedRows);
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
borderRadius: 9,
|
||||
child: Text(
|
||||
buttonLabel,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isControlButtonEnabled
|
||||
@ -178,6 +179,11 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
(device.updateTime ?? 0) * 1000)),
|
||||
];
|
||||
}).toList(),
|
||||
onSelectionChanged: (selectedRows) {
|
||||
context
|
||||
.read<DeviceManagementBloc>()
|
||||
.add(UpdateSelection(selectedRows));
|
||||
},
|
||||
initialSelectedIds: context
|
||||
.read<DeviceManagementBloc>()
|
||||
.selectedDevices
|
||||
|
@ -47,12 +47,15 @@ class ToggleWidget extends StatelessWidget {
|
||||
)
|
||||
: ClipOval(
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: 60,
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
icon ?? Assets.lightPulp,
|
||||
width: 60,
|
||||
height: 60,
|
||||
fit: BoxFit.cover,
|
||||
width: 35,
|
||||
height: 35,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
)),
|
||||
Text(
|
||||
|
@ -21,8 +21,10 @@ String formatTimeOfDayToISO(TimeOfDay time, {DateTime? currentDate}) {
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
// Convert DateTime to Unix timestamp (in seconds)
|
||||
final unixTimestamp = dateTime.millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
return dateTime.toUtc().toIso8601String();
|
||||
return unixTimestamp.toString();
|
||||
}
|
||||
|
||||
String formatIsoStringToTime(String isoString, BuildContext context) {
|
||||
|
Reference in New Issue
Block a user