mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
add batch controll box selection logic
This commit is contained in:
@ -11,8 +11,8 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
class AcDeviceControls extends StatelessWidget with HelperResponsiveLayout {
|
||||||
const AcDeviceControl({super.key, required this.device});
|
const AcDeviceControls({super.key, required this.device});
|
||||||
|
|
||||||
final AllDevicesModel device;
|
final AllDevicesModel device;
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class DeviceManagementBloc
|
|||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice: null,
|
selectedDevice: null,
|
||||||
|
isControlButtonEnabled: false,
|
||||||
));
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(DeviceManagementInitial());
|
emit(DeviceManagementInitial());
|
||||||
@ -69,8 +70,8 @@ class DeviceManagementBloc
|
|||||||
onlineCount: _onlineCount,
|
onlineCount: _onlineCount,
|
||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice:
|
selectedDevice: _selectedDevices.isNotEmpty ? _selectedDevices : null,
|
||||||
_selectedDevices.isNotEmpty ? _selectedDevices.first : null,
|
isControlButtonEnabled: _selectedDevices.isNotEmpty,
|
||||||
));
|
));
|
||||||
|
|
||||||
if (productName.isNotEmpty) {
|
if (productName.isNotEmpty) {
|
||||||
@ -92,6 +93,7 @@ class DeviceManagementBloc
|
|||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice: null,
|
selectedDevice: null,
|
||||||
|
isControlButtonEnabled: false,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +113,19 @@ class DeviceManagementBloc
|
|||||||
_selectedDevices.add(event.selectedDevice);
|
_selectedDevices.add(event.selectedDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isControlButtonEnabled = _selectedDevices.length == 1;
|
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
|
||||||
|
|
||||||
|
bool isControlButtonEnabled = false;
|
||||||
|
|
||||||
|
if (clonedSelectedDevices.length == 1) {
|
||||||
|
isControlButtonEnabled = true;
|
||||||
|
} else if (clonedSelectedDevices.length > 1) {
|
||||||
|
|
||||||
|
final productTypes =
|
||||||
|
clonedSelectedDevices.map((device) => device.productType).toSet();
|
||||||
|
isControlButtonEnabled = productTypes.length ==
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
emit(DeviceManagementLoaded(
|
emit(DeviceManagementLoaded(
|
||||||
@ -120,7 +134,9 @@ class DeviceManagementBloc
|
|||||||
onlineCount: _onlineCount,
|
onlineCount: _onlineCount,
|
||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice: isControlButtonEnabled ? _selectedDevices.first : null,
|
selectedDevice:
|
||||||
|
clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
|
||||||
|
isControlButtonEnabled: isControlButtonEnabled,
|
||||||
));
|
));
|
||||||
} else if (state is DeviceManagementFiltered) {
|
} else if (state is DeviceManagementFiltered) {
|
||||||
emit(DeviceManagementFiltered(
|
emit(DeviceManagementFiltered(
|
||||||
@ -129,7 +145,9 @@ class DeviceManagementBloc
|
|||||||
onlineCount: _onlineCount,
|
onlineCount: _onlineCount,
|
||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice: isControlButtonEnabled ? _selectedDevices.first : null,
|
selectedDevice:
|
||||||
|
clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
|
||||||
|
isControlButtonEnabled: isControlButtonEnabled,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,12 +176,10 @@ class DeviceManagementBloc
|
|||||||
|
|
||||||
void _onSearchDevices(
|
void _onSearchDevices(
|
||||||
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||||
// If the search fields are all empty, restore the last filtered devices
|
|
||||||
if ((event.community == null || event.community!.isEmpty) &&
|
if ((event.community == null || event.community!.isEmpty) &&
|
||||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||||
(event.productName == null || event.productName!.isEmpty)) {
|
(event.productName == null || event.productName!.isEmpty)) {
|
||||||
productName = '';
|
productName = '';
|
||||||
// If the current state is filtered, re-emit the filtered state
|
|
||||||
if (state is DeviceManagementFiltered) {
|
if (state is DeviceManagementFiltered) {
|
||||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
||||||
}
|
}
|
||||||
@ -214,6 +230,7 @@ class DeviceManagementBloc
|
|||||||
offlineCount: _offlineCount,
|
offlineCount: _offlineCount,
|
||||||
lowBatteryCount: _lowBatteryCount,
|
lowBatteryCount: _lowBatteryCount,
|
||||||
selectedDevice: null,
|
selectedDevice: null,
|
||||||
|
isControlButtonEnabled: false,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,8 @@ class DeviceManagementLoaded extends DeviceManagementState {
|
|||||||
final int onlineCount;
|
final int onlineCount;
|
||||||
final int offlineCount;
|
final int offlineCount;
|
||||||
final int lowBatteryCount;
|
final int lowBatteryCount;
|
||||||
final AllDevicesModel? selectedDevice;
|
final List<AllDevicesModel>? selectedDevice;
|
||||||
|
final bool isControlButtonEnabled;
|
||||||
|
|
||||||
const DeviceManagementLoaded({
|
const DeviceManagementLoaded({
|
||||||
required this.devices,
|
required this.devices,
|
||||||
@ -26,6 +27,7 @@ class DeviceManagementLoaded extends DeviceManagementState {
|
|||||||
required this.offlineCount,
|
required this.offlineCount,
|
||||||
required this.lowBatteryCount,
|
required this.lowBatteryCount,
|
||||||
this.selectedDevice,
|
this.selectedDevice,
|
||||||
|
required this.isControlButtonEnabled,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -35,7 +37,8 @@ class DeviceManagementLoaded extends DeviceManagementState {
|
|||||||
onlineCount,
|
onlineCount,
|
||||||
offlineCount,
|
offlineCount,
|
||||||
lowBatteryCount,
|
lowBatteryCount,
|
||||||
selectedDevice
|
selectedDevice,
|
||||||
|
isControlButtonEnabled
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +48,8 @@ class DeviceManagementFiltered extends DeviceManagementState {
|
|||||||
final int onlineCount;
|
final int onlineCount;
|
||||||
final int offlineCount;
|
final int offlineCount;
|
||||||
final int lowBatteryCount;
|
final int lowBatteryCount;
|
||||||
final AllDevicesModel? selectedDevice;
|
final List<AllDevicesModel>? selectedDevice;
|
||||||
|
final bool isControlButtonEnabled;
|
||||||
|
|
||||||
const DeviceManagementFiltered({
|
const DeviceManagementFiltered({
|
||||||
required this.filteredDevices,
|
required this.filteredDevices,
|
||||||
@ -54,6 +58,7 @@ class DeviceManagementFiltered extends DeviceManagementState {
|
|||||||
required this.offlineCount,
|
required this.offlineCount,
|
||||||
required this.lowBatteryCount,
|
required this.lowBatteryCount,
|
||||||
this.selectedDevice,
|
this.selectedDevice,
|
||||||
|
required this.isControlButtonEnabled,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -63,7 +68,8 @@ class DeviceManagementFiltered extends DeviceManagementState {
|
|||||||
onlineCount,
|
onlineCount,
|
||||||
offlineCount,
|
offlineCount,
|
||||||
lowBatteryCount,
|
lowBatteryCount,
|
||||||
selectedDevice
|
selectedDevice,
|
||||||
|
isControlButtonEnabled
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import 'package:syncrow_web/pages/device_managment/ceiling_sensor/view/ceiling_s
|
|||||||
import 'package:syncrow_web/pages/device_managment/curtain/view/curtain_status_view.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/view/curtain_status_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_status_view.dart';
|
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_status_view.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart';
|
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_device_control.dart';
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_device_control.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart';
|
import 'package:syncrow_web/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart';
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ mixin RouteControlsBasedCode {
|
|||||||
Widget routeControlsWidgets({required AllDevicesModel device}) {
|
Widget routeControlsWidgets({required AllDevicesModel device}) {
|
||||||
switch (device.productType) {
|
switch (device.productType) {
|
||||||
case '3G':
|
case '3G':
|
||||||
return LivingRoomDeviceControl(
|
return LivingRoomDeviceControls(
|
||||||
deviceId: device.uuid!,
|
deviceId: device.uuid!,
|
||||||
);
|
);
|
||||||
case 'GW':
|
case 'GW':
|
||||||
@ -21,7 +22,7 @@ mixin RouteControlsBasedCode {
|
|||||||
gatewayId: device.uuid!,
|
gatewayId: device.uuid!,
|
||||||
);
|
);
|
||||||
case 'DL':
|
case 'DL':
|
||||||
return DoorLockView(device: device);
|
return DoorLockControls(device: device);
|
||||||
case 'WPS':
|
case 'WPS':
|
||||||
return WallSensorControls(device: device);
|
return WallSensorControls(device: device);
|
||||||
case 'CPS':
|
case 'CPS':
|
||||||
@ -29,11 +30,43 @@ mixin RouteControlsBasedCode {
|
|||||||
device: device,
|
device: device,
|
||||||
);
|
);
|
||||||
case 'CUR':
|
case 'CUR':
|
||||||
return CurtainStatusView(
|
return CurtainStatusControls(
|
||||||
deviceId: device.uuid!,
|
deviceId: device.uuid!,
|
||||||
);
|
);
|
||||||
case 'AC':
|
case 'AC':
|
||||||
return AcDeviceControl(device: device);
|
return AcDeviceControls(device: device);
|
||||||
|
default:
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget routeBatchControlsWidgets({required List<AllDevicesModel> devices}) {
|
||||||
|
switch (devices.first.productType) {
|
||||||
|
case '3G':
|
||||||
|
return LivingRoomBatchControls(
|
||||||
|
deviceIds: devices
|
||||||
|
.where((e) => e.productType == '3G')
|
||||||
|
.map((e) => e.uuid!)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
// case 'GW':
|
||||||
|
// return GateWayControls(
|
||||||
|
// gatewayId: device.first.uuid!,
|
||||||
|
// );
|
||||||
|
// case 'DL':
|
||||||
|
// return DoorLockControls(device: device.first);
|
||||||
|
// case 'WPS':
|
||||||
|
// return WallSensorControls(device: device.first);
|
||||||
|
// case 'CPS':
|
||||||
|
// return CeilingSensorControls(
|
||||||
|
// device: device.first,
|
||||||
|
// );
|
||||||
|
// case 'CUR':
|
||||||
|
// return CurtainStatusControls(
|
||||||
|
// deviceId: device.first.uuid!,
|
||||||
|
// );
|
||||||
|
// case 'AC':
|
||||||
|
// return AcDeviceControls(device: device.first);
|
||||||
default:
|
default:
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
||||||
|
|
||||||
@ -154,4 +155,65 @@ class AllDevicesModel {
|
|||||||
data['battery'] = batteryLevel;
|
data['battery'] = batteryLevel;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is AllDevicesModel &&
|
||||||
|
other.room == room &&
|
||||||
|
other.unit == unit &&
|
||||||
|
other.productUuid == productUuid &&
|
||||||
|
other.productType == productType &&
|
||||||
|
other.permissionType == permissionType &&
|
||||||
|
other.activeTime == activeTime &&
|
||||||
|
other.category == category &&
|
||||||
|
other.categoryName == categoryName &&
|
||||||
|
other.createTime == createTime &&
|
||||||
|
other.gatewayId == gatewayId &&
|
||||||
|
other.icon == icon &&
|
||||||
|
other.ip == ip &&
|
||||||
|
other.lat == lat &&
|
||||||
|
other.localKey == localKey &&
|
||||||
|
other.lon == lon &&
|
||||||
|
other.model == model &&
|
||||||
|
other.name == name &&
|
||||||
|
other.nodeId == nodeId &&
|
||||||
|
other.online == online &&
|
||||||
|
other.ownerId == ownerId &&
|
||||||
|
other.sub == sub &&
|
||||||
|
other.timeZone == timeZone &&
|
||||||
|
other.updateTime == updateTime &&
|
||||||
|
other.uuid == uuid &&
|
||||||
|
other.batteryLevel == batteryLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return room.hashCode ^
|
||||||
|
unit.hashCode ^
|
||||||
|
productUuid.hashCode ^
|
||||||
|
productType.hashCode ^
|
||||||
|
permissionType.hashCode ^
|
||||||
|
activeTime.hashCode ^
|
||||||
|
category.hashCode ^
|
||||||
|
categoryName.hashCode ^
|
||||||
|
createTime.hashCode ^
|
||||||
|
gatewayId.hashCode ^
|
||||||
|
icon.hashCode ^
|
||||||
|
ip.hashCode ^
|
||||||
|
lat.hashCode ^
|
||||||
|
localKey.hashCode ^
|
||||||
|
lon.hashCode ^
|
||||||
|
model.hashCode ^
|
||||||
|
name.hashCode ^
|
||||||
|
nodeId.hashCode ^
|
||||||
|
online.hashCode ^
|
||||||
|
ownerId.hashCode ^
|
||||||
|
sub.hashCode ^
|
||||||
|
timeZone.hashCode ^
|
||||||
|
updateTime.hashCode ^
|
||||||
|
uuid.hashCode ^
|
||||||
|
batteryLevel.hashCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/custom_table.dart';
|
import 'package:syncrow_web/pages/common/custom_table.dart';
|
||||||
@ -27,6 +28,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
int offlineCount = 0;
|
int offlineCount = 0;
|
||||||
int lowBatteryCount = 0;
|
int lowBatteryCount = 0;
|
||||||
bool isControlButtonEnabled = false;
|
bool isControlButtonEnabled = false;
|
||||||
|
List<AllDevicesModel> selectedDevices = [];
|
||||||
|
|
||||||
if (state is DeviceManagementLoaded) {
|
if (state is DeviceManagementLoaded) {
|
||||||
devicesToShow = state.devices;
|
devicesToShow = state.devices;
|
||||||
@ -34,14 +36,18 @@ 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;
|
isControlButtonEnabled = state.isControlButtonEnabled;
|
||||||
|
selectedDevices = state.selectedDevice ??
|
||||||
|
context.read<DeviceManagementBloc>().selectedDevices;
|
||||||
} 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;
|
isControlButtonEnabled = state.isControlButtonEnabled;
|
||||||
|
selectedDevices = state.selectedDevice ??
|
||||||
|
context.read<DeviceManagementBloc>().selectedDevices;
|
||||||
} else if (state is DeviceManagementInitial) {
|
} else if (state is DeviceManagementInitial) {
|
||||||
devicesToShow = [];
|
devicesToShow = [];
|
||||||
selectedIndex = 0;
|
selectedIndex = 0;
|
||||||
@ -55,6 +61,9 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
'Low Battery ($lowBatteryCount)',
|
'Low Battery ($lowBatteryCount)',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
final buttonLabel =
|
||||||
|
(selectedDevices.length > 1) ? 'Batch Control' : 'Control';
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@ -69,7 +78,8 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
tabs: tabs,
|
tabs: tabs,
|
||||||
selectedIndex: selectedIndex,
|
selectedIndex: selectedIndex,
|
||||||
onTabChanged: (index) {
|
onTabChanged: (index) {
|
||||||
context.read<DeviceManagementBloc>()
|
context
|
||||||
|
.read<DeviceManagementBloc>()
|
||||||
.add(SelectedFilterChanged(index));
|
.add(SelectedFilterChanged(index));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -84,19 +94,32 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: isControlButtonEnabled
|
onPressed: isControlButtonEnabled
|
||||||
? () {
|
? () {
|
||||||
final selectedDevice = context
|
if (selectedDevices.length == 1) {
|
||||||
.read<DeviceManagementBloc>()
|
|
||||||
.selectedDevices.first;
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => DeviceControlDialog(
|
builder: (context) => DeviceControlDialog(
|
||||||
device: selectedDevice),
|
device: selectedDevices.first,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
} else if (selectedDevices.length > 1) {
|
||||||
|
final productTypes = selectedDevices
|
||||||
|
.map((device) => device.productType)
|
||||||
|
.toSet();
|
||||||
|
if (productTypes.length == 1) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) =>
|
||||||
|
DeviceBatchControlDialog(
|
||||||
|
devices: selectedDevices,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
borderRadius: 9,
|
borderRadius: 9,
|
||||||
child: Text(
|
child: Text(
|
||||||
'Control',
|
buttonLabel,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: isControlButtonEnabled
|
color: isControlButtonEnabled
|
||||||
|
@ -6,10 +6,11 @@ import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_event.da
|
|||||||
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_state.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain/bloc/curtain_state.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class CurtainStatusView extends StatelessWidget with HelperResponsiveLayout {
|
class CurtainStatusControls extends StatelessWidget
|
||||||
|
with HelperResponsiveLayout {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
|
|
||||||
const CurtainStatusView({super.key, required this.deviceId});
|
const CurtainStatusControls({super.key, required this.deviceId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -7,10 +7,10 @@ import 'package:syncrow_web/pages/device_managment/door_lock/bloc/door_lock_stat
|
|||||||
import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_status_model.dart';
|
import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_status_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/door_lock/widget/door_button.dart';
|
import 'package:syncrow_web/pages/device_managment/door_lock/widget/door_button.dart';
|
||||||
|
|
||||||
class DoorLockView extends StatelessWidget {
|
class DoorLockControls extends StatelessWidget {
|
||||||
final AllDevicesModel device;
|
final AllDevicesModel device;
|
||||||
|
|
||||||
const DoorLockView({super.key, required this.device});
|
const DoorLockControls({super.key, required this.device});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/helper/route_controls_based_code.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DeviceBatchControlDialog extends StatelessWidget
|
||||||
|
with RouteControlsBasedCode {
|
||||||
|
final List<AllDevicesModel> devices;
|
||||||
|
|
||||||
|
const DeviceBatchControlDialog({super.key, required this.devices});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Dialog(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
insetPadding: const EdgeInsets.all(20),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 798,
|
||||||
|
height: context.screenHeight * 0.7,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const SizedBox(),
|
||||||
|
Text(
|
||||||
|
devices.first.categoryName ?? 'Device Control',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 22,
|
||||||
|
color: ColorsManager.dialogBlueTitle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 25,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.transparent,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.grey,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: IconButton(
|
||||||
|
padding: EdgeInsets.all(1),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.close,
|
||||||
|
color: Colors.grey,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
//// BUILD DEVICE CONTROLS
|
||||||
|
///
|
||||||
|
//// ROUTE TO SPECIFIC CONTROL VIEW BASED ON DEVICE CATEGORY
|
||||||
|
routeBatchControlsWidgets(devices: devices),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -18,21 +18,25 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
LivingRoomBloc({required this.deviceId}) : super(LivingRoomInitial()) {
|
LivingRoomBloc({required this.deviceId}) : super(LivingRoomInitial()) {
|
||||||
on<LivingRoomFetchDeviceStatus>(_onFetchDeviceStatus);
|
on<LivingRoomFetchDeviceStatus>(_onFetchDeviceStatus);
|
||||||
on<LivingRoomControl>(_livingRoomControl);
|
on<LivingRoomControl>(_livingRoomControl);
|
||||||
|
on<LivingRoomFetchBatchStatus>(_livingRoomBatchControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onFetchDeviceStatus(
|
FutureOr<void> _onFetchDeviceStatus(
|
||||||
LivingRoomFetchDeviceStatus event, Emitter<LivingRoomState> emit) async {
|
LivingRoomFetchDeviceStatus event, Emitter<LivingRoomState> emit) async {
|
||||||
emit(LivingRoomDeviceStatusLoading());
|
emit(LivingRoomDeviceStatusLoading());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status =
|
||||||
deviceStatus = LivingRoomStatusModel.fromJson(event.deviceId, status.status);
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
|
deviceStatus =
|
||||||
|
LivingRoomStatusModel.fromJson(event.deviceId, status.status);
|
||||||
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(LivingRoomDeviceManagementError(e.toString()));
|
emit(LivingRoomDeviceManagementError(e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _livingRoomControl(LivingRoomControl event, Emitter<LivingRoomState> emit) async {
|
FutureOr<void> _livingRoomControl(
|
||||||
|
LivingRoomControl event, Emitter<LivingRoomState> emit) async {
|
||||||
final oldValue = _getValueByCode(event.code);
|
final oldValue = _getValueByCode(event.code);
|
||||||
|
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
@ -60,8 +64,8 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
}
|
}
|
||||||
_timer = Timer(const Duration(seconds: 1), () async {
|
_timer = Timer(const Duration(seconds: 1), () async {
|
||||||
try {
|
try {
|
||||||
final response =
|
final response = await DevicesManagementApi()
|
||||||
await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
|
.deviceControl(deviceId, Status(code: code, value: value));
|
||||||
if (!response) {
|
if (!response) {
|
||||||
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
||||||
}
|
}
|
||||||
@ -71,8 +75,8 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _revertValueAndEmit(
|
void _revertValueAndEmit(String deviceId, String code, dynamic oldValue,
|
||||||
String deviceId, String code, dynamic oldValue, Emitter<LivingRoomState> emit) {
|
Emitter<LivingRoomState> emit) {
|
||||||
_updateLocalValue(code, oldValue);
|
_updateLocalValue(code, oldValue);
|
||||||
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||||
emit(const LivingRoomControlError('Failed to control the device.'));
|
emit(const LivingRoomControlError('Failed to control the device.'));
|
||||||
@ -113,4 +117,20 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _livingRoomBatchControl(
|
||||||
|
LivingRoomFetchBatchStatus event, Emitter<LivingRoomState> emit) async {
|
||||||
|
emit(LivingRoomDeviceStatusLoading());
|
||||||
|
try {
|
||||||
|
//TODO: get batch status from api
|
||||||
|
/// for now sending one id and getting the same value from fetch status
|
||||||
|
final status =
|
||||||
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
|
deviceStatus =
|
||||||
|
LivingRoomStatusModel.fromJson(event.deviceId, status.status);
|
||||||
|
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||||
|
} catch (e) {
|
||||||
|
emit(LivingRoomDeviceManagementError(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,16 @@ class LivingRoomFetchDeviceStatus extends LivingRoomEvent {
|
|||||||
List<Object> get props => [deviceId];
|
List<Object> get props => [deviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//LivingRoomFetchBatchStatus
|
||||||
|
class LivingRoomFetchBatchStatus extends LivingRoomEvent {
|
||||||
|
final String deviceId;
|
||||||
|
|
||||||
|
const LivingRoomFetchBatchStatus(this.deviceId);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId];
|
||||||
|
}
|
||||||
|
|
||||||
class LivingRoomControl extends LivingRoomEvent {
|
class LivingRoomControl extends LivingRoomEvent {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String code;
|
final String code;
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/bloc/living_room_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/living_room_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/widgets/living_toggle_widget.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
|
class LivingRoomBatchControls extends StatelessWidget
|
||||||
|
with HelperResponsiveLayout {
|
||||||
|
const LivingRoomBatchControls({super.key, required this.deviceIds});
|
||||||
|
|
||||||
|
final List<String> deviceIds;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => LivingRoomBloc(deviceId: deviceIds.first)
|
||||||
|
..add(LivingRoomFetchBatchStatus(deviceIds.first)),
|
||||||
|
child: BlocBuilder<LivingRoomBloc, LivingRoomState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is LivingRoomDeviceStatusLoading) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
} else if (state is LivingRoomDeviceStatusLoaded) {
|
||||||
|
return _buildStatusControls(context, state.status);
|
||||||
|
} else if (state is LivingRoomDeviceManagementError ||
|
||||||
|
state is LivingRoomControlError) {
|
||||||
|
return const Center(child: Text('Error fetching status'));
|
||||||
|
} else {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildStatusControls(
|
||||||
|
BuildContext context, LivingRoomStatusModel status) {
|
||||||
|
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||||
|
final isLarge = isLargeScreenSize(context);
|
||||||
|
final isMedium = isMediumScreenSize(context);
|
||||||
|
return SizedBox(
|
||||||
|
child: GridView(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: isLarge || isExtraLarge
|
||||||
|
? 3
|
||||||
|
: isMedium
|
||||||
|
? 2
|
||||||
|
: 1,
|
||||||
|
mainAxisExtent: 140,
|
||||||
|
crossAxisSpacing: 12,
|
||||||
|
mainAxisSpacing: 12,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
ToggleWidget(
|
||||||
|
value: status.switch1,
|
||||||
|
code: 'switch_1',
|
||||||
|
deviceId: deviceIds.first,
|
||||||
|
label: 'Wall Light',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -5,23 +5,25 @@ import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/livi
|
|||||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/widgets/living_toggle_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/three_gang_switch/widgets/living_toggle_widget.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class LivingRoomDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
class LivingRoomDeviceControls extends StatelessWidget
|
||||||
|
with HelperResponsiveLayout {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
|
|
||||||
const LivingRoomDeviceControl({super.key, required this.deviceId});
|
const LivingRoomDeviceControls({super.key, required this.deviceId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) =>
|
create: (context) => LivingRoomBloc(deviceId: deviceId)
|
||||||
LivingRoomBloc(deviceId: deviceId)..add(LivingRoomFetchDeviceStatus(deviceId)),
|
..add(LivingRoomFetchDeviceStatus(deviceId)),
|
||||||
child: BlocBuilder<LivingRoomBloc, LivingRoomState>(
|
child: BlocBuilder<LivingRoomBloc, LivingRoomState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is LivingRoomDeviceStatusLoading) {
|
if (state is LivingRoomDeviceStatusLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else if (state is LivingRoomDeviceStatusLoaded) {
|
} else if (state is LivingRoomDeviceStatusLoaded) {
|
||||||
return _buildStatusControls(context, state.status);
|
return _buildStatusControls(context, state.status);
|
||||||
} else if (state is LivingRoomDeviceManagementError || state is LivingRoomControlError) {
|
} else if (state is LivingRoomDeviceManagementError ||
|
||||||
|
state is LivingRoomControlError) {
|
||||||
return const Center(child: Text('Error fetching status'));
|
return const Center(child: Text('Error fetching status'));
|
||||||
} else {
|
} else {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
@ -31,7 +33,8 @@ class LivingRoomDeviceControl extends StatelessWidget with HelperResponsiveLayou
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStatusControls(BuildContext context, LivingRoomStatusModel status) {
|
Widget _buildStatusControls(
|
||||||
|
BuildContext context, LivingRoomStatusModel status) {
|
||||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||||
final isLarge = isLargeScreenSize(context);
|
final isLarge = isLargeScreenSize(context);
|
||||||
final isMedium = isMediumScreenSize(context);
|
final isMedium = isMediumScreenSize(context);
|
||||||
|
24
pubspec.lock
24
pubspec.lock
@ -292,18 +292,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: leak_tracker
|
name: leak_tracker
|
||||||
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
|
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "10.0.4"
|
version: "10.0.5"
|
||||||
leak_tracker_flutter_testing:
|
leak_tracker_flutter_testing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: leak_tracker_flutter_testing
|
name: leak_tracker_flutter_testing
|
||||||
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
|
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.3"
|
version: "3.0.5"
|
||||||
leak_tracker_testing:
|
leak_tracker_testing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -340,18 +340,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
|
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.0"
|
version: "0.11.1"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
|
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.12.0"
|
version: "1.15.0"
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -561,10 +561,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
|
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.0"
|
version: "0.7.2"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -609,10 +609,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vm_service
|
name: vm_service
|
||||||
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
|
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "14.2.1"
|
version: "14.2.5"
|
||||||
web:
|
web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
Reference in New Issue
Block a user