mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fix selection for the devices
This commit is contained in:
@ -47,13 +47,10 @@ class _DynamicTableState extends State<DynamicTable> {
|
|||||||
|
|
||||||
void _toggleRowSelection(int index) {
|
void _toggleRowSelection(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
for (int i = 0; i < _selected.length; i++) {
|
_selected[index] = !_selected[index];
|
||||||
_selected[i] = false;
|
|
||||||
}
|
|
||||||
_selected[index] = true;
|
|
||||||
|
|
||||||
if (widget.onRowSelected != null) {
|
if (widget.onRowSelected != null) {
|
||||||
widget.onRowSelected!(index, true, widget.data[index]);
|
widget.onRowSelected!(index, _selected[index], widget.data[index]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
FutureOr<void> _onAcControl(AcControl event, Emitter<AcsState> emit) async {
|
FutureOr<void> _onAcControl(AcControl event, Emitter<AcsState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value, emit);
|
||||||
|
|
||||||
emit(ACStatusLoaded(deviceStatus));
|
emit(ACStatusLoaded(deviceStatus));
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
|
|
||||||
void _revertValueAndEmit(
|
void _revertValueAndEmit(
|
||||||
String deviceId, String code, dynamic oldValue, Emitter<AcsState> emit) {
|
String deviceId, String code, dynamic oldValue, Emitter<AcsState> emit) {
|
||||||
_updateLocalValue(code, oldValue);
|
_updateLocalValue(code, oldValue, emit);
|
||||||
emit(ACStatusLoaded(deviceStatus));
|
emit(ACStatusLoaded(deviceStatus));
|
||||||
emit(const AcsFailedState(error: 'Failed to control the device.'));
|
emit(const AcsFailedState(error: 'Failed to control the device.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateLocalValue(String code, dynamic value) {
|
void _updateLocalValue(String code, dynamic value, Emitter<AcsState> emit) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'switch':
|
case 'switch':
|
||||||
if (value is bool) {
|
if (value is bool) {
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
// import 'package:flutter/cupertino.dart';
|
|
||||||
// import 'package:syncrow_web/pages/device_managment/ac/control_list/ac_mode.dart';
|
|
||||||
// import 'package:syncrow_web/pages/device_managment/ac/control_list/ac_toggle.dart';
|
|
||||||
// import 'package:syncrow_web/pages/device_managment/ac/control_list/current_temp.dart';
|
|
||||||
// import 'package:syncrow_web/utils/constants/assets.dart';
|
|
||||||
|
|
||||||
// mixin ACHelper {
|
|
||||||
// Widget acHelperControlWidgets({
|
|
||||||
// required dynamic value,
|
|
||||||
// required String code,
|
|
||||||
// required String deviceId,
|
|
||||||
// }) {
|
|
||||||
// switch (code) {
|
|
||||||
// case 'switch':
|
|
||||||
// return AcToggle(value: value, code: code, deviceId: deviceId);
|
|
||||||
// case 'temp_current':
|
|
||||||
// return CurrentTemp(value: value, code: 'temp_set', deviceId: deviceId);
|
|
||||||
// case 'temp_set':
|
|
||||||
// return SizedBox();
|
|
||||||
// case 'mode':
|
|
||||||
// return AcMode(value: value, code: code, deviceId: deviceId);
|
|
||||||
// case 'level':
|
|
||||||
// return SizedBox();
|
|
||||||
// case 'child_lock':
|
|
||||||
// return AcToggle(
|
|
||||||
// value: value,
|
|
||||||
// code: code,
|
|
||||||
// deviceId: deviceId,
|
|
||||||
// icon: Assets.childLock,
|
|
||||||
// description: 'Child Lock');
|
|
||||||
// default:
|
|
||||||
// return const SizedBox();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
@ -13,7 +13,7 @@ class DeviceManagementBloc
|
|||||||
int _onlineCount = 0;
|
int _onlineCount = 0;
|
||||||
int _offlineCount = 0;
|
int _offlineCount = 0;
|
||||||
int _lowBatteryCount = 0;
|
int _lowBatteryCount = 0;
|
||||||
AllDevicesModel? _selectedDevice;
|
List<AllDevicesModel> _selectedDevices = [];
|
||||||
|
|
||||||
DeviceManagementBloc() : super(DeviceManagementInitial()) {
|
DeviceManagementBloc() : super(DeviceManagementInitial()) {
|
||||||
on<FetchDevices>(_onFetchDevices);
|
on<FetchDevices>(_onFetchDevices);
|
||||||
@ -75,7 +75,33 @@ class DeviceManagementBloc
|
|||||||
|
|
||||||
void _onSelectDevice(
|
void _onSelectDevice(
|
||||||
SelectDevice event, Emitter<DeviceManagementState> emit) {
|
SelectDevice event, Emitter<DeviceManagementState> emit) {
|
||||||
_selectedDevice = event.selectedDevice;
|
if (_selectedDevices.contains(event.selectedDevice)) {
|
||||||
|
_selectedDevices.remove(event.selectedDevice);
|
||||||
|
} else {
|
||||||
|
_selectedDevices.add(event.selectedDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isControlButtonEnabled = _selectedDevices.length == 1;
|
||||||
|
|
||||||
|
if (state is DeviceManagementLoaded) {
|
||||||
|
emit(DeviceManagementLoaded(
|
||||||
|
devices: _devices,
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onlineCount: _onlineCount,
|
||||||
|
offlineCount: _offlineCount,
|
||||||
|
lowBatteryCount: _lowBatteryCount,
|
||||||
|
selectedDevice: isControlButtonEnabled ? _selectedDevices.first : null,
|
||||||
|
));
|
||||||
|
} else if (state is DeviceManagementFiltered) {
|
||||||
|
emit(DeviceManagementFiltered(
|
||||||
|
filteredDevices: (state as DeviceManagementFiltered).filteredDevices,
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onlineCount: _onlineCount,
|
||||||
|
offlineCount: _offlineCount,
|
||||||
|
lowBatteryCount: _lowBatteryCount,
|
||||||
|
selectedDevice: isControlButtonEnabled ? _selectedDevices.first : null,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _calculateDeviceCounts() {
|
void _calculateDeviceCounts() {
|
||||||
@ -135,5 +161,5 @@ class DeviceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AllDevicesModel? get selectedDevice => _selectedDevice;
|
List<AllDevicesModel> get selectedDevices => _selectedDevices;
|
||||||
}
|
}
|
||||||
|
@ -66,3 +66,12 @@ class DeviceManagementFiltered extends DeviceManagementState {
|
|||||||
selectedDevice
|
selectedDevice
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DeviceSelectionUpdated extends DeviceManagementState {
|
||||||
|
final List<AllDevicesModel> selectedDevices;
|
||||||
|
|
||||||
|
const DeviceSelectionUpdated(this.selectedDevices);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [selectedDevices];
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
int onlineCount = 0;
|
int onlineCount = 0;
|
||||||
int offlineCount = 0;
|
int offlineCount = 0;
|
||||||
int lowBatteryCount = 0;
|
int lowBatteryCount = 0;
|
||||||
|
bool isControlButtonEnabled = false;
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
devicesToShow = state.devices;
|
devicesToShow = state.devices;
|
||||||
@ -33,12 +34,14 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
onlineCount = state.onlineCount;
|
onlineCount = state.onlineCount;
|
||||||
offlineCount = state.offlineCount;
|
offlineCount = state.offlineCount;
|
||||||
lowBatteryCount = state.lowBatteryCount;
|
lowBatteryCount = state.lowBatteryCount;
|
||||||
|
isControlButtonEnabled = state.selectedDevice != null;
|
||||||
} else if (state is DeviceManagementFiltered) {
|
} else if (state is DeviceManagementFiltered) {
|
||||||
devicesToShow = state.filteredDevices;
|
devicesToShow = state.filteredDevices;
|
||||||
selectedIndex = state.selectedIndex;
|
selectedIndex = state.selectedIndex;
|
||||||
onlineCount = state.onlineCount;
|
onlineCount = state.onlineCount;
|
||||||
offlineCount = state.offlineCount;
|
offlineCount = state.offlineCount;
|
||||||
lowBatteryCount = state.lowBatteryCount;
|
lowBatteryCount = state.lowBatteryCount;
|
||||||
|
isControlButtonEnabled = state.selectedDevice != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final tabs = [
|
final tabs = [
|
||||||
@ -77,20 +80,28 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
decoration: containerDecoration,
|
decoration: containerDecoration,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: () {
|
onPressed: isControlButtonEnabled
|
||||||
final selectedDevice = context
|
? () {
|
||||||
.read<DeviceManagementBloc>()
|
final selectedDevice = context
|
||||||
.selectedDevice;
|
.read<DeviceManagementBloc>()
|
||||||
if (selectedDevice != null) {
|
.selectedDevices
|
||||||
showDialog(
|
.first;
|
||||||
context: context,
|
showDialog(
|
||||||
builder: (context) =>
|
context: context,
|
||||||
DeviceControlDialog(device: selectedDevice),
|
builder: (context) => DeviceControlDialog(
|
||||||
);
|
device: selectedDevice),
|
||||||
}
|
);
|
||||||
},
|
}
|
||||||
|
: null,
|
||||||
borderRadius: 9,
|
borderRadius: 9,
|
||||||
child: const Text('Control'),
|
child: Text(
|
||||||
|
'Control',
|
||||||
|
style: TextStyle(
|
||||||
|
color: isControlButtonEnabled
|
||||||
|
? Colors.white
|
||||||
|
: Colors.grey,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -106,11 +117,10 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
child: DynamicTable(
|
child: DynamicTable(
|
||||||
cellDecoration: containerDecoration,
|
cellDecoration: containerDecoration,
|
||||||
onRowSelected: (index, isSelected, row) {
|
onRowSelected: (index, isSelected, row) {
|
||||||
if (isSelected) {
|
final selectedDevice = devicesToShow[index];
|
||||||
context
|
context
|
||||||
.read<DeviceManagementBloc>()
|
.read<DeviceManagementBloc>()
|
||||||
.add(SelectDevice(devicesToShow[index]));
|
.add(SelectDevice(selectedDevice));
|
||||||
}
|
|
||||||
},
|
},
|
||||||
withCheckBox: true,
|
withCheckBox: true,
|
||||||
size: context.screenSize,
|
size: context.screenSize,
|
||||||
|
Reference in New Issue
Block a user