mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 13:24:55 +00:00
formatted all files.
This commit is contained in:
@ -45,7 +45,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
||||
if (deviceStatus.countdown1 != 0) {
|
||||
final totalMinutes = deviceStatus.countdown1 * 6;
|
||||
@ -71,21 +72,20 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
void _listenToChanges(deviceId) {
|
||||
try {
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
final stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) async {
|
||||
ref.onValue.listen((DatabaseEvent event) async {
|
||||
if (event.snapshot.value == null) return;
|
||||
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(Status(code: element['code'], value: element['value']));
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus = AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||
if (!isClosed) {
|
||||
add(AcStatusUpdated(deviceStatus));
|
||||
}
|
||||
@ -129,8 +129,10 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
@ -190,8 +192,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
void _handleIncreaseTime(IncreaseTimeEvent event, Emitter<AcsState> emit) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
int newHours = scheduledHours;
|
||||
int newMinutes = scheduledMinutes + 30;
|
||||
var newHours = scheduledHours;
|
||||
var newMinutes = scheduledMinutes + 30;
|
||||
newHours += newMinutes ~/ 60;
|
||||
newMinutes = newMinutes % 60;
|
||||
if (newHours > 23) {
|
||||
@ -213,7 +215,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
int totalMinutes = (scheduledHours * 60) + scheduledMinutes;
|
||||
var totalMinutes = (scheduledHours * 60) + scheduledMinutes;
|
||||
totalMinutes = (totalMinutes - 30).clamp(0, 1440);
|
||||
scheduledHours = totalMinutes ~/ 60;
|
||||
scheduledMinutes = totalMinutes % 60;
|
||||
@ -286,7 +288,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
void _startCountdownTimer(Emitter<AcsState> emit) {
|
||||
_countdownTimer?.cancel();
|
||||
int totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
|
||||
var totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
|
||||
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (totalSeconds > 0) {
|
||||
@ -336,32 +338,26 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(acSwitch: value);
|
||||
}
|
||||
break;
|
||||
case 'temp_set':
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(tempSet: value);
|
||||
}
|
||||
break;
|
||||
case 'mode':
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(modeString: value);
|
||||
}
|
||||
break;
|
||||
case 'level':
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(fanSpeedsString: value);
|
||||
}
|
||||
break;
|
||||
case 'child_lock':
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(childLock: value);
|
||||
}
|
||||
break;
|
||||
case 'countdown_time':
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(countdown1: value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class AcFetchDeviceStatusEvent extends AcsEvent {
|
||||
|
||||
class AcStatusUpdated extends AcsEvent {
|
||||
final AcStatusModel deviceStatus;
|
||||
AcStatusUpdated(this.deviceStatus);
|
||||
const AcStatusUpdated(this.deviceStatus);
|
||||
}
|
||||
|
||||
class AcFetchBatchStatusEvent extends AcsEvent {
|
||||
@ -77,8 +77,6 @@ class AcFactoryResetEvent extends AcsEvent {
|
||||
List<Object> get props => [deviceId, factoryResetModel];
|
||||
}
|
||||
|
||||
|
||||
|
||||
class OnClose extends AcsEvent {}
|
||||
|
||||
class IncreaseTimeEvent extends AcsEvent {
|
||||
@ -95,8 +93,7 @@ class ToggleScheduleEvent extends AcsEvent {}
|
||||
|
||||
class TimerCompletedEvent extends AcsEvent {}
|
||||
|
||||
class UpdateTimerEvent extends AcsEvent {
|
||||
}
|
||||
class UpdateTimerEvent extends AcsEvent {}
|
||||
|
||||
class ApiCountdownValueEvent extends AcsEvent {
|
||||
final int apiValue;
|
||||
|
||||
@ -18,6 +18,7 @@ class ACStatusLoaded extends AcsState {
|
||||
final DateTime timestamp;
|
||||
final int scheduledHours;
|
||||
final int scheduledMinutes;
|
||||
@override
|
||||
final bool isTimerActive;
|
||||
|
||||
ACStatusLoaded({
|
||||
@ -72,5 +73,3 @@ class TimerRunInProgress extends AcsState {
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -32,9 +32,9 @@ class AcStatusModel {
|
||||
late int currentTemp;
|
||||
late String fanSpeeds;
|
||||
late bool childLock;
|
||||
late int _countdown1 = 0;
|
||||
late var countdown1 = 0;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch':
|
||||
acSwitch = status.value ?? false;
|
||||
@ -55,7 +55,7 @@ class AcStatusModel {
|
||||
childLock = status.value ?? false;
|
||||
break;
|
||||
case 'countdown_time':
|
||||
_countdown1 = status.value ?? 0;
|
||||
countdown1 = status.value ?? 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@ class AcStatusModel {
|
||||
currentTemp: currentTemp,
|
||||
fanSpeedsString: fanSpeeds,
|
||||
childLock: childLock,
|
||||
countdown1: _countdown1,
|
||||
countdown1: countdown1,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,8 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class AcDeviceBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class AcDeviceBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const AcDeviceBatchControlView({super.key, required this.devicesIds});
|
||||
|
||||
final List<String> devicesIds;
|
||||
@ -100,8 +101,8 @@ class AcDeviceBatchControlView extends StatelessWidget with HelperResponsiveLayo
|
||||
),
|
||||
Text(
|
||||
'h',
|
||||
style:
|
||||
context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor),
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.blackColor),
|
||||
),
|
||||
Text(
|
||||
'30',
|
||||
@ -148,7 +149,8 @@ class AcDeviceBatchControlView extends StatelessWidget with HelperResponsiveLayo
|
||||
callFactoryReset: () {
|
||||
context.read<AcBloc>().add(AcFactoryResetEvent(
|
||||
deviceId: state.status.uuid,
|
||||
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
|
||||
factoryResetModel:
|
||||
FactoryResetModel(devicesUuid: devicesIds),
|
||||
));
|
||||
},
|
||||
),
|
||||
|
||||
@ -14,7 +14,7 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
const AcDeviceControlsView({super.key, required this.device});
|
||||
const AcDeviceControlsView({super.key, required this.device});
|
||||
|
||||
final AllDevicesModel device;
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class _CurrentTempState extends State<BatchCurrentTemp> {
|
||||
|
||||
double _initialAdjustedValue(dynamic value) {
|
||||
if (value is int || value is double) {
|
||||
double doubleValue = value.toDouble();
|
||||
final double doubleValue = value.toDouble();
|
||||
return doubleValue > 99 ? doubleValue / 10 : doubleValue;
|
||||
} else {
|
||||
throw ArgumentError('Invalid value type: Expected int or double');
|
||||
@ -75,35 +75,48 @@ class _CurrentTempState extends State<BatchCurrentTemp> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
widget.isBatch == true
|
||||
? Text(
|
||||
'Set Temperature',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
|
||||
)
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
if (widget.isBatch == true)
|
||||
Text(
|
||||
'Set Temperature',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.grey),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Current Temperature',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.grey),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Current Temperature',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
(widget.currentTemp > 99 ? widget.currentTemp / 10 : widget.currentTemp).toString(),
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
|
||||
),
|
||||
const CelsiusSymbol(
|
||||
color: Colors.grey,
|
||||
)
|
||||
],
|
||||
(widget.currentTemp > 99
|
||||
? widget.currentTemp / 10
|
||||
: widget.currentTemp)
|
||||
.toString(),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.grey),
|
||||
),
|
||||
const CelsiusSymbol(
|
||||
color: Colors.grey,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
IncrementDecrementWidget(
|
||||
value: _adjustedValue.toString(),
|
||||
|
||||
@ -52,7 +52,7 @@ class AcToggle extends StatelessWidget {
|
||||
height: 20,
|
||||
width: 35,
|
||||
child: CupertinoSwitch(
|
||||
activeColor: ColorsManager.dialogBlueTitle,
|
||||
activeTrackColor: ColorsManager.dialogBlueTitle,
|
||||
value: value,
|
||||
onChanged: (newValue) {
|
||||
context.read<AcBloc>().add(
|
||||
|
||||
@ -39,7 +39,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
|
||||
double _initialAdjustedValue(dynamic value) {
|
||||
if (value is int || value is double) {
|
||||
double doubleValue = value.toDouble();
|
||||
final double doubleValue = value.toDouble();
|
||||
return doubleValue > 99 ? doubleValue / 10 : doubleValue;
|
||||
} else {
|
||||
throw ArgumentError('Invalid value type: Expected int or double');
|
||||
@ -60,6 +60,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(CurrentTemp oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
@ -69,6 +70,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
@ -87,7 +89,10 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
children: [
|
||||
Text(
|
||||
'Current Temperature',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.grey),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
@ -95,8 +100,14 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
(widget.currentTemp > 99 ? widget.currentTemp / 10 : widget.currentTemp).toString(),
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
|
||||
(widget.currentTemp > 99
|
||||
? widget.currentTemp / 10
|
||||
: widget.currentTemp)
|
||||
.toString(),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(color: Colors.grey),
|
||||
),
|
||||
const CelsiusSymbol(
|
||||
color: Colors.grey,
|
||||
|
||||
@ -16,7 +16,7 @@ class DeviceManagementBloc
|
||||
int _onlineCount = 0;
|
||||
int _offlineCount = 0;
|
||||
int _lowBatteryCount = 0;
|
||||
List<AllDevicesModel> _selectedDevices = [];
|
||||
final List<AllDevicesModel> _selectedDevices = [];
|
||||
List<AllDevicesModel> _filteredDevices = [];
|
||||
String currentProductName = '';
|
||||
String? currentCommunity;
|
||||
@ -37,20 +37,21 @@ class DeviceManagementBloc
|
||||
FetchDevices event, Emitter<DeviceManagementState> emit) async {
|
||||
emit(DeviceManagementLoading());
|
||||
try {
|
||||
List<AllDevicesModel> devices = [];
|
||||
var devices = <AllDevicesModel>[];
|
||||
_devices.clear();
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
final spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
devices =
|
||||
await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
} else {
|
||||
for (var community in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
for (final community in spaceBloc.state.selectedCommunities) {
|
||||
final spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||
for (var space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||
community, space, projectUuid));
|
||||
for (final space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi()
|
||||
.fetchDevices(community, space, projectUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,7 +74,7 @@ class DeviceManagementBloc
|
||||
}
|
||||
}
|
||||
|
||||
void _onFilterDevices(
|
||||
Future<void> _onFilterDevices(
|
||||
FilterDevices event, Emitter<DeviceManagementState> emit) async {
|
||||
if (_devices.isNotEmpty) {
|
||||
_filteredDevices = List.from(_devices.where((device) {
|
||||
@ -165,9 +166,9 @@ class DeviceManagementBloc
|
||||
_selectedDevices.add(event.selectedDevice);
|
||||
}
|
||||
|
||||
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
|
||||
final clonedSelectedDevices = List<AllDevicesModel>.from(_selectedDevices);
|
||||
|
||||
bool isControlButtonEnabled =
|
||||
final isControlButtonEnabled =
|
||||
_checkIfControlButtonEnabled(clonedSelectedDevices);
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
@ -197,8 +198,8 @@ class DeviceManagementBloc
|
||||
|
||||
void _onUpdateSelection(
|
||||
UpdateSelection event, Emitter<DeviceManagementState> emit) {
|
||||
List<AllDevicesModel> selectedDevices = [];
|
||||
List<AllDevicesModel> devicesToSelectFrom = [];
|
||||
final selectedDevices = <AllDevicesModel>[];
|
||||
var devicesToSelectFrom = <AllDevicesModel>[];
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
|
||||
@ -206,7 +207,7 @@ class DeviceManagementBloc
|
||||
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
|
||||
}
|
||||
|
||||
for (int i = 0; i < event.selectedRows.length; i++) {
|
||||
for (var i = 0; i < event.selectedRows.length; i++) {
|
||||
if (event.selectedRows[i]) {
|
||||
selectedDevices.add(devicesToSelectFrom[i]);
|
||||
}
|
||||
@ -294,7 +295,7 @@ class DeviceManagementBloc
|
||||
currentCommunity = event.community;
|
||||
currentUnitName = event.unitName;
|
||||
|
||||
List<AllDevicesModel> devicesToSearch = _filteredDevices;
|
||||
final devicesToSearch = _filteredDevices;
|
||||
|
||||
if (devicesToSearch.isNotEmpty) {
|
||||
final filteredDevices = devicesToSearch.where((device) {
|
||||
|
||||
@ -18,6 +18,7 @@ import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dar
|
||||
import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_sensor_batch_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_batch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_switch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart';
|
||||
@ -39,8 +40,6 @@ import 'package:syncrow_web/pages/device_managment/water_heater/view/water_heate
|
||||
import 'package:syncrow_web/pages/device_managment/water_leak/view/water_leak_batch_control_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/water_leak/view/water_leak_control_view.dart';
|
||||
|
||||
import '../../one_g_glass_switch/view/one_gang_glass_switch_control_view.dart';
|
||||
|
||||
mixin RouteControlsBasedCode {
|
||||
Widget routeControlsWidgets({required AllDevicesModel device}) {
|
||||
switch (device.productType) {
|
||||
@ -107,7 +106,7 @@ mixin RouteControlsBasedCode {
|
||||
case 'SOS':
|
||||
return SosDeviceControlsView(device: device);
|
||||
|
||||
case 'NCPS':
|
||||
case 'NCPS':
|
||||
return FlushMountedPresenceSensorControlView(device: device);
|
||||
default:
|
||||
return const SizedBox();
|
||||
@ -132,76 +131,133 @@ mixin RouteControlsBasedCode {
|
||||
switch (devices.first.productType) {
|
||||
case '1G':
|
||||
return WallLightBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == '1G')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '1G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case '2G':
|
||||
return TwoGangBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == '2G')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '2G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case '3G':
|
||||
return LivingRoomBatchControlsView(
|
||||
deviceIds: devices.where((e) => (e.productType == '3G')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '3G')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case '1GT':
|
||||
return OneGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == '1GT')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '1GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case '2GT':
|
||||
return TwoGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == '2GT')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '2GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case '3GT':
|
||||
return ThreeGangGlassSwitchBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == '3GT')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == '3GT')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'GW':
|
||||
return GatewayBatchControlView(
|
||||
gatewayIds: devices.where((e) => (e.productType == 'GW')).map((e) => e.uuid!).toList(),
|
||||
gatewayIds: devices
|
||||
.where((e) => e.productType == 'GW')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'DL':
|
||||
return DoorLockBatchControlView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'DL')).map((e) => e.uuid!).toList());
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'DL')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
case 'WPS':
|
||||
return WallSensorBatchControlView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'WPS')).map((e) => e.uuid!).toList());
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'WPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
case 'CPS':
|
||||
return CeilingSensorBatchControlView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'CPS')).map((e) => e.uuid!).toList(),
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'CPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'CUR':
|
||||
return CurtainBatchStatusView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'CUR')).map((e) => e.uuid!).toList(),
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'CUR')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'AC':
|
||||
return AcDeviceBatchControlView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'AC')).map((e) => e.uuid!).toList());
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'AC')
|
||||
.map((e) => e.uuid!)
|
||||
.toList());
|
||||
case 'WH':
|
||||
return WaterHEaterBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == 'WH')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'WH')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'DS':
|
||||
return MainDoorSensorBatchView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'DS')).map((e) => e.uuid!).toList(),
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'DS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'GD':
|
||||
return GarageDoorBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == 'GD')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'GD')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'WL':
|
||||
return WaterLeakBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == 'WL')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'WL')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'PC':
|
||||
return PowerClampBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == 'PC')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'PC')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'SOS':
|
||||
return SOSBatchControlView(
|
||||
deviceIds: devices.where((e) => (e.productType == 'SOS')).map((e) => e.uuid!).toList(),
|
||||
deviceIds: devices
|
||||
.where((e) => e.productType == 'SOS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
case 'NCPS':
|
||||
return FlushMountedPresenceSensorBatchControlView(
|
||||
devicesIds: devices.where((e) => (e.productType == 'NCPS')).map((e) => e.uuid!).toList(),
|
||||
devicesIds: devices
|
||||
.where((e) => e.productType == 'NCPS')
|
||||
.map((e) => e.uuid!)
|
||||
.toList(),
|
||||
);
|
||||
default:
|
||||
return const SizedBox();
|
||||
|
||||
@ -5,7 +5,12 @@ class DeviceSubSpace {
|
||||
String? subspaceName;
|
||||
bool? disabled;
|
||||
|
||||
DeviceSubSpace({this.id, this.createdAt, this.updatedAt, this.subspaceName, this.disabled});
|
||||
DeviceSubSpace(
|
||||
{this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
this.subspaceName,
|
||||
this.disabled});
|
||||
|
||||
DeviceSubSpace.fromJson(Map<String, dynamic> json) {
|
||||
id = json['uuid']?.toString() ?? '';
|
||||
|
||||
@ -212,8 +212,8 @@ PC
|
||||
SOS
|
||||
|
||||
*/
|
||||
DeviceType type = devicesTypesMap[productType] ?? DeviceType.Other;
|
||||
String tempIcon = '';
|
||||
final type = devicesTypesMap[productType] ?? DeviceType.Other;
|
||||
var tempIcon = '';
|
||||
if (type == DeviceType.LightBulb) {
|
||||
tempIcon = Assets.lightBulb;
|
||||
} else if (type == DeviceType.CeilingSensor ||
|
||||
@ -441,13 +441,9 @@ SOS
|
||||
VoltageCStatusFunction(
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
CurrentCStatusFunction(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF'),
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
PowerFactorCStatusFunction(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF'),
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||
];
|
||||
|
||||
default:
|
||||
@ -565,23 +561,23 @@ SOS
|
||||
}
|
||||
|
||||
Map<String, DeviceType> devicesTypesMap = {
|
||||
"AC": DeviceType.AC,
|
||||
"GW": DeviceType.Gateway,
|
||||
"CPS": DeviceType.CeilingSensor,
|
||||
"DL": DeviceType.DoorLock,
|
||||
"WPS": DeviceType.WallSensor,
|
||||
"3G": DeviceType.ThreeGang,
|
||||
"2G": DeviceType.TwoGang,
|
||||
"1G": DeviceType.OneGang,
|
||||
"CUR": DeviceType.Curtain,
|
||||
"WH": DeviceType.WH,
|
||||
"DS": DeviceType.DS,
|
||||
"1GT": DeviceType.OneTouch,
|
||||
"2GT": DeviceType.TowTouch,
|
||||
"3GT": DeviceType.ThreeTouch,
|
||||
"GD": DeviceType.GarageDoor,
|
||||
"WL": DeviceType.WaterLeak,
|
||||
"NCPS": DeviceType.NCPS,
|
||||
"PC": DeviceType.PC,
|
||||
'AC': DeviceType.AC,
|
||||
'GW': DeviceType.Gateway,
|
||||
'CPS': DeviceType.CeilingSensor,
|
||||
'DL': DeviceType.DoorLock,
|
||||
'WPS': DeviceType.WallSensor,
|
||||
'3G': DeviceType.ThreeGang,
|
||||
'2G': DeviceType.TwoGang,
|
||||
'1G': DeviceType.OneGang,
|
||||
'CUR': DeviceType.Curtain,
|
||||
'WH': DeviceType.WH,
|
||||
'DS': DeviceType.DS,
|
||||
'1GT': DeviceType.OneTouch,
|
||||
'2GT': DeviceType.TowTouch,
|
||||
'3GT': DeviceType.ThreeTouch,
|
||||
'GD': DeviceType.GarageDoor,
|
||||
'WL': DeviceType.WaterLeak,
|
||||
'NCPS': DeviceType.NCPS,
|
||||
'PC': DeviceType.PC,
|
||||
};
|
||||
}
|
||||
|
||||
@ -6,13 +6,13 @@ class FactoryResetModel {
|
||||
|
||||
FactoryResetModel({
|
||||
required this.devicesUuid,
|
||||
this.operationType = "RESET",
|
||||
this.operationType = 'RESET',
|
||||
});
|
||||
|
||||
factory FactoryResetModel.fromJson(Map<String, dynamic> json) {
|
||||
return FactoryResetModel(
|
||||
devicesUuid: List<String>.from(json['devicesUuid']),
|
||||
operationType: "RESET",
|
||||
operationType: 'RESET',
|
||||
);
|
||||
}
|
||||
|
||||
@ -58,4 +58,3 @@ class FactoryResetModel {
|
||||
@override
|
||||
int get hashCode => devicesUuid.hashCode;
|
||||
}
|
||||
|
||||
|
||||
@ -24,13 +24,13 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
||||
builder: (context, state) {
|
||||
List<AllDevicesModel> devicesToShow = [];
|
||||
int selectedIndex = 0;
|
||||
int onlineCount = 0;
|
||||
int offlineCount = 0;
|
||||
int lowBatteryCount = 0;
|
||||
bool isControlButtonEnabled = false;
|
||||
List<AllDevicesModel> selectedDevices = [];
|
||||
var devicesToShow = <AllDevicesModel>[];
|
||||
var selectedIndex = 0;
|
||||
var onlineCount = 0;
|
||||
var offlineCount = 0;
|
||||
var lowBatteryCount = 0;
|
||||
var isControlButtonEnabled = false;
|
||||
var selectedDevices = <AllDevicesModel>[];
|
||||
|
||||
if (state is DeviceManagementLoaded) {
|
||||
devicesToShow = state.devices;
|
||||
@ -194,18 +194,23 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
device.name ?? '',
|
||||
device.productName ?? '',
|
||||
device.uuid ?? '',
|
||||
(device.spaces != null &&
|
||||
device.spaces!.isNotEmpty)
|
||||
? device.spaces![0].spaceName
|
||||
: '',
|
||||
if (device.spaces != null &&
|
||||
device.spaces!.isNotEmpty)
|
||||
device.spaces![0].spaceName
|
||||
else
|
||||
'',
|
||||
combinedSpaceNames,
|
||||
device.batteryLevel != null
|
||||
? '${device.batteryLevel}%'
|
||||
: '-',
|
||||
if (device.batteryLevel != null)
|
||||
'${device.batteryLevel}%'
|
||||
else
|
||||
'-',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
(device.createTime ?? 0) * 1000)),
|
||||
device.online == true ? 'Online' : 'Offline',
|
||||
if (device.online == true)
|
||||
'Online'
|
||||
else
|
||||
'Offline',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
(device.updateTime ?? 0) * 1000)),
|
||||
@ -243,7 +248,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
showGeneralDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: "Device Settings",
|
||||
barrierLabel: 'Device Settings',
|
||||
transitionDuration: const Duration(milliseconds: 300),
|
||||
pageBuilder: (context, anim1, anim2) {
|
||||
return Align(
|
||||
|
||||
@ -33,9 +33,9 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
||||
spacing: 20,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
_buildSearchField("Space Name", _unitNameController, 200),
|
||||
_buildSearchField('Space Name', _unitNameController, 200),
|
||||
_buildSearchField(
|
||||
"Device Name / Product Name", _productNameController, 300),
|
||||
'Device Name / Product Name', _productNameController, 300),
|
||||
_buildSearchResetButtons(),
|
||||
],
|
||||
);
|
||||
|
||||
@ -37,7 +37,8 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
||||
) async {
|
||||
emit(CeilingLoadingInitialState());
|
||||
try {
|
||||
final response = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final response =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = CeilingSensorModel.fromJson(response.status);
|
||||
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||
_listenToChanges(event.deviceId);
|
||||
@ -54,11 +55,12 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
||||
stream.listen((DatabaseEvent event) {
|
||||
if (event.snapshot.value == null) return;
|
||||
|
||||
final usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
final statusList = <Status>[];
|
||||
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList.add(Status(code: element['code'], value: element['value']));
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
});
|
||||
|
||||
deviceStatus = CeilingSensorModel.fromJson(statusList);
|
||||
@ -178,7 +180,8 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
||||
) async {
|
||||
emit(CeilingLoadingInitialState());
|
||||
try {
|
||||
final response = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final response =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = CeilingSensorModel.fromJson(response.status);
|
||||
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||
} catch (e) {
|
||||
|
||||
@ -85,8 +85,6 @@ class CeilingFactoryResetEvent extends CeilingSensorEvent {
|
||||
List<Object> get props => [devicesId, factoryResetModel];
|
||||
}
|
||||
|
||||
|
||||
|
||||
class StatusUpdated extends CeilingSensorEvent {
|
||||
final CeilingSensorModel deviceStatus;
|
||||
const StatusUpdated(this.deviceStatus);
|
||||
|
||||
@ -26,48 +26,53 @@ class CeilingSensorModel {
|
||||
});
|
||||
|
||||
factory CeilingSensorModel.fromJson(List<Status> jsonList) {
|
||||
late String _presenceState = 'none';
|
||||
late int _sensitivity = 1;
|
||||
late String _checkingResult = '';
|
||||
int _presenceRange = 1;
|
||||
int _sportsPara = 1;
|
||||
String _bodyMovement = 'none';
|
||||
String _noBodyTime = 'none';
|
||||
int _maxDis = 0;
|
||||
SpaceTypes _spaceType = SpaceTypes.none;
|
||||
late var presenceState = 'none';
|
||||
late var sensitivity = 1;
|
||||
late var checkingResult = '';
|
||||
var presenceRange = 1;
|
||||
var sportsPara = 1;
|
||||
var bodyMovement = 'none';
|
||||
var noBodyTime = 'none';
|
||||
var maxDis = 0;
|
||||
var spaceType = SpaceTypes.none;
|
||||
|
||||
try {
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'presence_state':
|
||||
_presenceState = status.value ?? 'none';
|
||||
presenceState = status.value ?? 'none';
|
||||
break;
|
||||
case 'scene':
|
||||
_spaceType = getSpaceType(status.value ?? 'none');
|
||||
spaceType = getSpaceType(status.value ?? 'none');
|
||||
break;
|
||||
case 'sensitivity':
|
||||
_sensitivity =
|
||||
status.value is int ? status.value : int.tryParse(status.value ?? '1') ?? 1;
|
||||
sensitivity = status.value is int
|
||||
? status.value
|
||||
: int.tryParse(status.value ?? '1') ?? 1;
|
||||
break;
|
||||
case 'checking_result':
|
||||
_checkingResult = status.value ?? '';
|
||||
checkingResult = status.value ?? '';
|
||||
break;
|
||||
case 'presence_range':
|
||||
_presenceRange =
|
||||
status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
|
||||
presenceRange = status.value is int
|
||||
? status.value
|
||||
: int.tryParse(status.value ?? '0') ?? 0;
|
||||
break;
|
||||
case 'sports_para':
|
||||
_sportsPara =
|
||||
status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
|
||||
sportsPara = status.value is int
|
||||
? status.value
|
||||
: int.tryParse(status.value ?? '0') ?? 0;
|
||||
break;
|
||||
case 'body_movement':
|
||||
_bodyMovement = status.value ?? '';
|
||||
bodyMovement = status.value ?? '';
|
||||
break;
|
||||
case 'nobody_time':
|
||||
_noBodyTime = status.value ?? 'none';
|
||||
noBodyTime = status.value ?? 'none';
|
||||
break;
|
||||
case 'moving_max_dis':
|
||||
_maxDis = status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
|
||||
maxDis = status.value is int
|
||||
? status.value
|
||||
: int.tryParse(status.value ?? '0') ?? 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -76,15 +81,15 @@ class CeilingSensorModel {
|
||||
}
|
||||
|
||||
return CeilingSensorModel(
|
||||
presenceState: _presenceState,
|
||||
sensitivity: _sensitivity,
|
||||
checkingResult: _checkingResult,
|
||||
presenceRange: _presenceRange,
|
||||
sportsPara: _sportsPara,
|
||||
bodyMovement: _bodyMovement,
|
||||
noBodyTime: _noBodyTime,
|
||||
maxDistance: _maxDis,
|
||||
spaceType: _spaceType,
|
||||
presenceState: presenceState,
|
||||
sensitivity: sensitivity,
|
||||
checkingResult: checkingResult,
|
||||
presenceRange: presenceRange,
|
||||
sportsPara: sportsPara,
|
||||
bodyMovement: bodyMovement,
|
||||
noBodyTime: noBodyTime,
|
||||
maxDistance: maxDis,
|
||||
spaceType: spaceType,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,8 @@ import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presen
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presense_nobody_time.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class CeilingSensorBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class CeilingSensorBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const CeilingSensorBatchControlView({super.key, required this.devicesIds});
|
||||
|
||||
final List<String> devicesIds;
|
||||
@ -28,11 +29,12 @@ class CeilingSensorBatchControlView extends StatelessWidget with HelperResponsiv
|
||||
)..add(CeilingFetchDeviceStatusEvent(devicesIds)),
|
||||
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is CeilingLoadingInitialState || state is CeilingReportsLoadingState) {
|
||||
if (state is CeilingLoadingInitialState ||
|
||||
state is CeilingReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is CeilingUpdateState) {
|
||||
return _buildGridView(
|
||||
context, state.ceilingSensorModel, isExtraLarge, isLarge, isMedium);
|
||||
return _buildGridView(context, state.ceilingSensorModel,
|
||||
isExtraLarge, isLarge, isMedium);
|
||||
}
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
},
|
||||
@ -40,8 +42,8 @@ class CeilingSensorBatchControlView extends StatelessWidget with HelperResponsiv
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGridView(BuildContext context, CeilingSensorModel model, bool isExtraLarge,
|
||||
bool isLarge, bool isMedium) {
|
||||
Widget _buildGridView(BuildContext context, CeilingSensorModel model,
|
||||
bool isExtraLarge, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
@ -116,7 +118,8 @@ class CeilingSensorBatchControlView extends StatelessWidget with HelperResponsiv
|
||||
context.read<CeilingSensorBloc>().add(
|
||||
CeilingFactoryResetEvent(
|
||||
devicesId: devicesIds.first,
|
||||
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
|
||||
factoryResetModel:
|
||||
FactoryResetModel(devicesUuid: devicesIds),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -34,7 +34,8 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
) async {
|
||||
emit(CurtainStatusLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(event.deviceId, emit);
|
||||
deviceStatus = _checkStatus(status.status[0].value);
|
||||
emit(CurtainStatusLoaded(deviceStatus));
|
||||
@ -54,7 +55,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
|
||||
final statusList = <Status>[];
|
||||
if (data['status'] != null) {
|
||||
for (var element in data['status']) {
|
||||
for (final element in data['status']) {
|
||||
statusList.add(
|
||||
Status(
|
||||
code: element['code'].toString(),
|
||||
@ -121,7 +122,8 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
) async {
|
||||
emit(CurtainStatusLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = _checkStatus(status.status[0].value);
|
||||
emit(CurtainStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
|
||||
@ -60,7 +60,8 @@ class CurtainFactoryReset extends CurtainEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceId, factoryReset];
|
||||
}
|
||||
|
||||
class StatusUpdated extends CurtainEvent {
|
||||
final bool deviceStatus;
|
||||
const StatusUpdated(this.deviceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
sealed class CurtainState extends Equatable {
|
||||
sealed class CurtainState extends Equatable {
|
||||
const CurtainState();
|
||||
|
||||
@override
|
||||
|
||||
@ -12,8 +12,8 @@ class CurtainModel {
|
||||
});
|
||||
|
||||
factory CurtainModel.fromJson(dynamic json) {
|
||||
var statusList = json['status'] as List;
|
||||
List<Status> status = statusList.map((i) => Status.fromJson(i)).toList();
|
||||
final statusList = json['status'] as List;
|
||||
final status = statusList.map((i) => Status.fromJson(i)).toList();
|
||||
|
||||
return CurtainModel(
|
||||
productUuid: json['productUuid'],
|
||||
|
||||
@ -10,7 +10,8 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class CurtainBatchStatusView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class CurtainBatchStatusView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const CurtainBatchStatusView({super.key, required this.devicesIds});
|
||||
|
||||
final List<String> devicesIds;
|
||||
@ -18,8 +19,8 @@ class CurtainBatchStatusView extends StatelessWidget with HelperResponsiveLayout
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
CurtainBlocFactory.create(deviceId: devicesIds.first)..add(CurtainFetchBatchStatus(devicesIds)),
|
||||
create: (context) => CurtainBlocFactory.create(deviceId: devicesIds.first)
|
||||
..add(CurtainFetchBatchStatus(devicesIds)),
|
||||
child: BlocBuilder<CurtainBloc, CurtainState>(
|
||||
builder: (context, state) {
|
||||
if (state is CurtainStatusLoading) {
|
||||
|
||||
@ -2,12 +2,13 @@ import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
|
||||
part 'setting_bloc_event.dart';
|
||||
|
||||
class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
@ -37,7 +38,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
|
||||
String? _fullNameValidator(String? value) {
|
||||
if (value == null) return 'name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r'\s+'), ' ').trim();
|
||||
if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) {
|
||||
return 'name must be between 2 and 30 characters long';
|
||||
}
|
||||
@ -66,8 +67,8 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
DeviceSettingInitialInfo event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
var response = await DevicesManagementApi.getDeviceInfo(deviceId);
|
||||
DeviceInfoModel deviceInfo = DeviceInfoModel.fromJson(response);
|
||||
final response = await DevicesManagementApi.getDeviceInfo(deviceId);
|
||||
final deviceInfo = DeviceInfoModel.fromJson(response);
|
||||
nameController.text = deviceInfo.name;
|
||||
emit(DeviceSettingsUpdate(
|
||||
deviceName: nameController.text,
|
||||
@ -92,9 +93,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
));
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
Future.delayed(const Duration(milliseconds: 500), focusNode.requestFocus);
|
||||
} else {
|
||||
add(const SettingBlocSaveName());
|
||||
focusNode.unfocus();
|
||||
@ -106,7 +105,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
));
|
||||
}
|
||||
|
||||
void _deleteDevice(
|
||||
Future<void> _deleteDevice(
|
||||
SettingBlocDeleteDevice event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
@ -123,7 +122,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onAssignDevice(
|
||||
Future<void> _onAssignDevice(
|
||||
SettingBlocAssignRoom event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
@ -143,7 +142,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchRooms(
|
||||
Future<void> _fetchRooms(
|
||||
SettingBlocFetchRooms event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
|
||||
@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_icon_type_helper.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_management_content.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/remove_device_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
@ -38,7 +38,7 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
builder: (context) {
|
||||
return BlocBuilder<SettingDeviceBloc, DeviceSettingsState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = context.read<SettingDeviceBloc>();
|
||||
final bloc = context.read<SettingDeviceBloc>();
|
||||
final iconPath = DeviceIconTypeHelper.getDeviceIconByTypeCode(
|
||||
device.productType);
|
||||
final deviceInfo = state is DeviceSettingsUpdate
|
||||
@ -73,7 +73,7 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: ColorsManager.vividBlue
|
||||
.withOpacity(0.7),
|
||||
.withValues(alpha: 0.7),
|
||||
fontSize: 24),
|
||||
),
|
||||
],
|
||||
@ -87,8 +87,8 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: CircleAvatar(
|
||||
radius: 38,
|
||||
backgroundColor:
|
||||
ColorsManager.grayBorder.withOpacity(0.5),
|
||||
backgroundColor: ColorsManager.grayBorder
|
||||
.withValues(alpha: 0.5),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
radius: 36,
|
||||
@ -128,14 +128,14 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
fontSize: 16,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
focusNode: _bloc.focusNode,
|
||||
controller: _bloc.nameController,
|
||||
enabled: _bloc.editName,
|
||||
focusNode: bloc.focusNode,
|
||||
controller: bloc.nameController,
|
||||
enabled: bloc.editName,
|
||||
onFieldSubmitted: (value) {
|
||||
_bloc.add(const ChangeNameEvent(
|
||||
bloc.add(const ChangeNameEvent(
|
||||
value: false));
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
border: InputBorder.none,
|
||||
@ -151,11 +151,11 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
height: 25,
|
||||
child: Visibility(
|
||||
visible:
|
||||
_bloc.editName != true,
|
||||
bloc.editName != true,
|
||||
replacement: const SizedBox(),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
_bloc.add(
|
||||
bloc.add(
|
||||
const ChangeNameEvent(
|
||||
value: true));
|
||||
},
|
||||
@ -192,14 +192,14 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
deviceInfo: deviceInfo,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
RemoveDeviceWidget(bloc: _bloc),
|
||||
RemoveDeviceWidget(bloc: bloc),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (state is DeviceSettingsLoading)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
child: ColoredBox(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: ColorsManager.primaryColor,
|
||||
|
||||
@ -20,9 +20,9 @@ class SubSpaceModel {
|
||||
}
|
||||
|
||||
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
List<DeviceModel> devices = [];
|
||||
final devices = <DeviceModel>[];
|
||||
if (json['devices'] != null) {
|
||||
for (var device in json['devices']) {
|
||||
for (final device in json['devices']) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,11 +12,11 @@ class SubSpaceDialog extends StatefulWidget {
|
||||
final void Function(SubSpaceModel?) onConfirmed;
|
||||
|
||||
const SubSpaceDialog({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.subSpaces,
|
||||
this.selected,
|
||||
required this.onConfirmed,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
State<SubSpaceDialog> createState() => _SubSpaceDialogState();
|
||||
@ -63,7 +63,7 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
_selectedId = value;
|
||||
});
|
||||
},
|
||||
activeColor: Color(0xFF2962FF),
|
||||
activeColor: const Color(0xFF2962FF),
|
||||
title: Text(
|
||||
space.name ?? 'Unnamed Sub-Space',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
@ -75,7 +75,7 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
controlAffinity: ListTileControlAffinity.trailing,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
);
|
||||
}).toList(),
|
||||
}),
|
||||
const SizedBox(height: 12),
|
||||
const Divider(height: 1, thickness: 1),
|
||||
SubSpaceDialogButtons(selectedId: _selectedId, widget: widget),
|
||||
|
||||
@ -22,17 +22,15 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
|
||||
on<StatusUpdated>(_onStatusUpdated);
|
||||
}
|
||||
|
||||
_listenToChanges(deviceId) {
|
||||
void _listenToChanges(deviceId) {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
final stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) {
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_status_model.dart';
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ class DoorLockStatusModel {
|
||||
late String remoteNoDpKey;
|
||||
late bool normalOpenSwitch;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'unlock_fingerprint':
|
||||
unlockFingerprint = status.value ?? 0;
|
||||
|
||||
@ -7,7 +7,8 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class DoorLockBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class DoorLockBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const DoorLockBatchControlView({super.key, required this.devicesIds});
|
||||
|
||||
final List<String> devicesIds;
|
||||
|
||||
@ -90,7 +90,7 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
color: Colors.grey.withValues(alpha: 0.5),
|
||||
blurRadius: 18,
|
||||
blurStyle: BlurStyle.outer,
|
||||
),
|
||||
|
||||
@ -15,8 +15,8 @@ import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
part 'flush_mounted_presence_sensor_event.dart';
|
||||
part 'flush_mounted_presence_sensor_state.dart';
|
||||
|
||||
class FlushMountedPresenceSensorBloc
|
||||
extends Bloc<FlushMountedPresenceSensorEvent, FlushMountedPresenceSensorState> {
|
||||
class FlushMountedPresenceSensorBloc extends Bloc<
|
||||
FlushMountedPresenceSensorEvent, FlushMountedPresenceSensorState> {
|
||||
final String deviceId;
|
||||
final ControlDeviceService controlDeviceService;
|
||||
final BatchControlDevicesService batchControlDevicesService;
|
||||
@ -54,7 +54,7 @@ class FlushMountedPresenceSensorBloc
|
||||
);
|
||||
}
|
||||
|
||||
void _onFlushMountedPresenceSensorFetchStatusEvent(
|
||||
Future<void> _onFlushMountedPresenceSensorFetchStatusEvent(
|
||||
FlushMountedPresenceSensorFetchStatusEvent event,
|
||||
Emitter<FlushMountedPresenceSensorState> emit,
|
||||
) async {
|
||||
@ -76,7 +76,8 @@ class FlushMountedPresenceSensorBloc
|
||||
) async {
|
||||
emit(FlushMountedPresenceSensorLoadingInitialState());
|
||||
try {
|
||||
final response = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final response =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = FlushMountedPresenceSensorModel.fromJson(response.status);
|
||||
emit(FlushMountedPresenceSensorUpdateState(model: deviceStatus));
|
||||
} catch (e) {
|
||||
@ -91,9 +92,9 @@ class FlushMountedPresenceSensorBloc
|
||||
);
|
||||
|
||||
ref.onValue.listen((event) {
|
||||
final eventsMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final eventsMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
eventsMap['status'].forEach((element) {
|
||||
statusList.add(
|
||||
Status(code: element['code'], value: element['value']),
|
||||
@ -113,7 +114,7 @@ class FlushMountedPresenceSensorBloc
|
||||
}
|
||||
}
|
||||
|
||||
void _onFlushMountedPresenceSensorChangeValueEvent(
|
||||
Future<void> _onFlushMountedPresenceSensorChangeValueEvent(
|
||||
FlushMountedPresenceSensorChangeValueEvent event,
|
||||
Emitter<FlushMountedPresenceSensorState> emit,
|
||||
) async {
|
||||
@ -196,7 +197,8 @@ class FlushMountedPresenceSensorBloc
|
||||
deviceReport: value, code: event.code));
|
||||
});
|
||||
} catch (e) {
|
||||
emit(FlushMountedPresenceSensorDeviceReportsFailedState(error: e.toString()));
|
||||
emit(FlushMountedPresenceSensorDeviceReportsFailedState(
|
||||
error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,8 @@ class FlushMountedPresenceSensorGetDeviceReportsEvent
|
||||
class FlushMountedPresenceSensorShowDescriptionEvent
|
||||
extends FlushMountedPresenceSensorEvent {
|
||||
final String description;
|
||||
const FlushMountedPresenceSensorShowDescriptionEvent({required this.description});
|
||||
const FlushMountedPresenceSensorShowDescriptionEvent(
|
||||
{required this.description});
|
||||
}
|
||||
|
||||
class FlushMountedPresenceSensorBackToGridViewEvent
|
||||
|
||||
@ -13,7 +13,8 @@ class FlushMountedPresenceSensorInitialState
|
||||
class FlushMountedPresenceSensorLoadingInitialState
|
||||
extends FlushMountedPresenceSensorState {}
|
||||
|
||||
class FlushMountedPresenceSensorUpdateState extends FlushMountedPresenceSensorState {
|
||||
class FlushMountedPresenceSensorUpdateState
|
||||
extends FlushMountedPresenceSensorState {
|
||||
final FlushMountedPresenceSensorModel model;
|
||||
const FlushMountedPresenceSensorUpdateState({required this.model});
|
||||
|
||||
@ -30,7 +31,8 @@ class FlushMountedPresenceSensorLoadingNewSate
|
||||
List<Object> get props => [model];
|
||||
}
|
||||
|
||||
class FlushMountedPresenceSensorFailedState extends FlushMountedPresenceSensorState {
|
||||
class FlushMountedPresenceSensorFailedState
|
||||
extends FlushMountedPresenceSensorState {
|
||||
final String error;
|
||||
|
||||
const FlushMountedPresenceSensorFailedState({required this.error});
|
||||
@ -58,7 +60,8 @@ class FlushMountedPresenceSensorDeviceReportsState
|
||||
|
||||
class FlushMountedPresenceSensorDeviceReportsFailedState
|
||||
extends FlushMountedPresenceSensorState {
|
||||
const FlushMountedPresenceSensorDeviceReportsFailedState({required this.error});
|
||||
const FlushMountedPresenceSensorDeviceReportsFailedState(
|
||||
{required this.error});
|
||||
|
||||
final String error;
|
||||
|
||||
@ -68,7 +71,8 @@ class FlushMountedPresenceSensorDeviceReportsFailedState
|
||||
|
||||
class FlushMountedPresenceSensorShowDescriptionState
|
||||
extends FlushMountedPresenceSensorState {
|
||||
const FlushMountedPresenceSensorShowDescriptionState({required this.description});
|
||||
const FlushMountedPresenceSensorShowDescriptionState(
|
||||
{required this.description});
|
||||
|
||||
final String description;
|
||||
@override
|
||||
|
||||
@ -9,8 +9,10 @@ abstract final class FlushMountedPresenceSensorBlocFactory {
|
||||
}) {
|
||||
return FlushMountedPresenceSensorBloc(
|
||||
deviceId: deviceId,
|
||||
controlDeviceService: DeviceBlocDependenciesFactory.createControlDeviceService(),
|
||||
batchControlDevicesService: DeviceBlocDependenciesFactory.createBatchControlDevicesService(),
|
||||
controlDeviceService:
|
||||
DeviceBlocDependenciesFactory.createControlDeviceService(),
|
||||
batchControlDevicesService:
|
||||
DeviceBlocDependenciesFactory.createBatchControlDevicesService(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,18 +37,18 @@ class FlushMountedPresenceSensorModel {
|
||||
int sensiReduce;
|
||||
|
||||
factory FlushMountedPresenceSensorModel.fromJson(List<Status> jsonList) {
|
||||
String presenceState = 'none';
|
||||
int sensitivity = 0;
|
||||
int nearDetection = 0;
|
||||
int farDetection = 0;
|
||||
String checkingResult = 'none';
|
||||
int presenceDelay = 0;
|
||||
int noneDelay = 0;
|
||||
int occurDistReduce = 0;
|
||||
int illuminance = 0;
|
||||
int sensiReduce = 0;
|
||||
var presenceState = 'none';
|
||||
var sensitivity = 0;
|
||||
var nearDetection = 0;
|
||||
var farDetection = 0;
|
||||
var checkingResult = 'none';
|
||||
var presenceDelay = 0;
|
||||
var noneDelay = 0;
|
||||
var occurDistReduce = 0;
|
||||
var illuminance = 0;
|
||||
var sensiReduce = 0;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case codePresenceState:
|
||||
presenceState = status.value ?? 'presence';
|
||||
@ -97,7 +97,3 @@ class FlushMountedPresenceSensorModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -66,13 +66,14 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 9,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeSensitivity,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeSensitivity,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.nearDetection / 100).clamp(0.0, double.infinity),
|
||||
@ -114,13 +115,14 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: model.occurDistReduce.toDouble(),
|
||||
@ -128,16 +130,17 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeOccurDistReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeOccurDistReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.presenceDelay / 10).toDouble(),
|
||||
value: model.presenceDelay / 10,
|
||||
title: 'Target Confirm Time:',
|
||||
description: 's',
|
||||
minValue: 0.0,
|
||||
@ -154,7 +157,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: ((model.noneDelay / 10).toDouble()),
|
||||
value: model.noneDelay / 10,
|
||||
description: 's',
|
||||
title: 'Disappe Delay:',
|
||||
minValue: 20,
|
||||
|
||||
@ -15,7 +15,8 @@ import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_la
|
||||
|
||||
class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const FlushMountedPresenceSensorControlView({required this.device, super.key});
|
||||
const FlushMountedPresenceSensorControlView(
|
||||
{required this.device, super.key});
|
||||
|
||||
final AllDevicesModel device;
|
||||
|
||||
@ -37,9 +38,9 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
return ReportsTable(
|
||||
report: state.deviceReport,
|
||||
thirdColumnTitle:
|
||||
state.code == 'illuminance_value' ? "Value" : 'Status',
|
||||
state.code == 'illuminance_value' ? 'Value' : 'Status',
|
||||
thirdColumnDescription:
|
||||
state.code == 'illuminance_value' ? "Lux" : null,
|
||||
state.code == 'illuminance_value' ? 'Lux' : null,
|
||||
onRowTap: (index) {},
|
||||
onClose: () {
|
||||
context
|
||||
@ -56,7 +57,8 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
.add(FlushMountedPresenceSensorBackToGridViewEvent());
|
||||
},
|
||||
);
|
||||
} else if (state is FlushMountedPresenceSensorDeviceReportsFailedState) {
|
||||
} else if (state
|
||||
is FlushMountedPresenceSensorDeviceReportsFailedState) {
|
||||
final model =
|
||||
context.read<FlushMountedPresenceSensorBloc>().deviceStatus;
|
||||
return _buildGridView(context, model);
|
||||
@ -105,12 +107,13 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 9,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeSensitivity,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeSensitivity,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.nearDetection / 100).clamp(0.0, double.infinity),
|
||||
@ -150,12 +153,13 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: model.occurDistReduce.toDouble(),
|
||||
@ -163,15 +167,16 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeOccurDistReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
action: (int value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeOccurDistReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.presenceDelay / 10).toDouble(),
|
||||
value: model.presenceDelay / 10,
|
||||
valuesPercision: 1,
|
||||
title: 'Target Confirm Time:',
|
||||
description: 's',
|
||||
@ -187,7 +192,7 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.noneDelay / 10).toDouble(),
|
||||
value: model.noneDelay / 10,
|
||||
description: 's',
|
||||
title: 'Disappe Delay:',
|
||||
minValue: 20,
|
||||
|
||||
@ -2,7 +2,6 @@ import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:firebase_database/firebase_database.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||
@ -42,17 +41,15 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
on<EditGarageDoorScheduleEvent>(_onEditSchedule);
|
||||
on<StatusUpdated>(_onStatusUpdated);
|
||||
}
|
||||
_listenToChanges(deviceId) {
|
||||
void _listenToChanges(deviceId) {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
final stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) {
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
@ -72,11 +69,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||
}
|
||||
|
||||
void _fetchGarageDoorStatus(
|
||||
Future<void> _fetchGarageDoorStatus(
|
||||
GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
|
||||
emit(GarageDoorLoadingState());
|
||||
try {
|
||||
var response =
|
||||
final response =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = GarageDoorStatusModel.fromJson(deviceId, response.status);
|
||||
_listenToChanges(deviceId);
|
||||
@ -103,13 +100,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
Future<void> _addSchedule(
|
||||
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
||||
try {
|
||||
ScheduleEntry newSchedule = ScheduleEntry(
|
||||
final newSchedule = ScheduleEntry(
|
||||
category: event.category,
|
||||
time: formatTimeOfDayToISO(event.time),
|
||||
function: Status(code: 'doorcontact_state', value: event.functionOn),
|
||||
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
|
||||
);
|
||||
bool success =
|
||||
final success =
|
||||
await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
|
||||
if (success) {
|
||||
add(FetchGarageDoorSchedulesEvent(
|
||||
@ -156,7 +153,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
}
|
||||
return schedule;
|
||||
}).toList();
|
||||
bool success = await DevicesManagementApi().updateScheduleRecord(
|
||||
final success = await DevicesManagementApi().updateScheduleRecord(
|
||||
enable: event.enable,
|
||||
uuid: deviceStatus.uuid,
|
||||
scheduleId: event.scheduleId,
|
||||
@ -175,7 +172,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event,
|
||||
Emitter<GarageDoorState> emit) async {
|
||||
try {
|
||||
bool success = await DevicesManagementApi()
|
||||
final success = await DevicesManagementApi()
|
||||
.deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
|
||||
if (success) {
|
||||
final updatedSchedules = deviceStatus.schedules
|
||||
@ -195,7 +192,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
Emitter<GarageDoorState> emit) async {
|
||||
emit(ScheduleGarageLoadingState());
|
||||
try {
|
||||
List<ScheduleModel> schedules = await DevicesManagementApi()
|
||||
final schedules = await DevicesManagementApi()
|
||||
.getDeviceSchedules(deviceStatus.uuid, event.category);
|
||||
deviceStatus = deviceStatus.copyWith(schedules: schedules);
|
||||
emit(
|
||||
@ -226,7 +223,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
|
||||
final currentState = state;
|
||||
if (currentState is GarageDoorLoadedState) {
|
||||
List<bool> updatedDays = List.from(currentState.selectedDays);
|
||||
final updatedDays = List<bool>.from(currentState.selectedDays);
|
||||
updatedDays[event.dayIndex] = event.isSelected;
|
||||
emit(currentState.copyWith(
|
||||
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
|
||||
@ -264,9 +261,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
.subtract(const Duration(days: 30))
|
||||
.millisecondsSinceEpoch;
|
||||
final to = DateTime.now().millisecondsSinceEpoch;
|
||||
final DeviceReport records =
|
||||
await DevicesManagementApi.getDeviceReportsByDate(
|
||||
event.deviceId, 'switch_1', from.toString(), to.toString());
|
||||
final records = await DevicesManagementApi.getDeviceReportsByDate(
|
||||
event.deviceId, 'switch_1', from.toString(), to.toString());
|
||||
emit(GarageDoorReportsState(deviceReport: records));
|
||||
} catch (e) {
|
||||
emit(GarageDoorReportsFailedState(error: e.toString()));
|
||||
@ -352,12 +348,12 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _increaseDelay(
|
||||
Future<void> _increaseDelay(
|
||||
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
||||
// if (deviceStatus.countdown1 != 0) {
|
||||
try {
|
||||
deviceStatus = deviceStatus.copyWith(
|
||||
delay: deviceStatus.delay + Duration(minutes: 10));
|
||||
delay: deviceStatus.delay + const Duration(minutes: 10));
|
||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||
add(GarageDoorControlEvent(
|
||||
deviceId: deviceId,
|
||||
@ -369,13 +365,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
// }
|
||||
}
|
||||
|
||||
void _decreaseDelay(
|
||||
Future<void> _decreaseDelay(
|
||||
DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
||||
// if (deviceStatus.countdown1 != 0) {
|
||||
try {
|
||||
if (deviceStatus.delay.inMinutes > 10) {
|
||||
deviceStatus = deviceStatus.copyWith(
|
||||
delay: deviceStatus.delay - Duration(minutes: 10));
|
||||
delay: deviceStatus.delay - const Duration(minutes: 10));
|
||||
}
|
||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||
add(GarageDoorControlEvent(
|
||||
@ -388,7 +384,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
//}
|
||||
}
|
||||
|
||||
void _garageDoorControlEvent(
|
||||
Future<void> _garageDoorControlEvent(
|
||||
GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
|
||||
final oldValue = event.code == 'countdown_1'
|
||||
? deviceStatus.countdown1
|
||||
@ -489,14 +485,14 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
||||
FutureOr<void> _onEditSchedule(
|
||||
EditGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
||||
try {
|
||||
ScheduleEntry newSchedule = ScheduleEntry(
|
||||
final newSchedule = ScheduleEntry(
|
||||
scheduleId: event.scheduleId,
|
||||
category: event.category,
|
||||
time: formatTimeOfDayToISO(event.time),
|
||||
function: Status(code: 'doorcontact_state', value: event.functionOn),
|
||||
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
|
||||
);
|
||||
bool success = await DevicesManagementApi()
|
||||
final success = await DevicesManagementApi()
|
||||
.editScheduleRecord(deviceId, newSchedule);
|
||||
if (success) {
|
||||
add(FetchGarageDoorSchedulesEvent(
|
||||
|
||||
@ -18,7 +18,7 @@ class GarageDoorDialogHelper {
|
||||
final bloc = context.read<GarageDoorBloc>();
|
||||
|
||||
if (schedule == null) {
|
||||
bloc.add((const UpdateSelectedTimeEvent(null)));
|
||||
bloc.add(const UpdateSelectedTimeEvent(null));
|
||||
bloc.add(InitializeAddScheduleEvent(
|
||||
selectedTime: null,
|
||||
selectedDays: List.filled(7, false),
|
||||
@ -77,9 +77,10 @@ class GarageDoorDialogHelper {
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
borderRadius: 15,
|
||||
onPressed: () async {
|
||||
TimeOfDay? time = await showTimePicker(
|
||||
final time = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: state.selectedTime ?? TimeOfDay.now(),
|
||||
initialTime:
|
||||
state.selectedTime ?? TimeOfDay.now(),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
@ -99,7 +100,9 @@ class GarageDoorDialogHelper {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
state.selectedTime == null ? 'Time' : state.selectedTime!.format(context),
|
||||
state.selectedTime == null
|
||||
? 'Time'
|
||||
: state.selectedTime!.format(context),
|
||||
style: context.textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
),
|
||||
@ -114,7 +117,8 @@ class GarageDoorDialogHelper {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildDayCheckboxes(context, state.selectedDays, isEdit: isEdit),
|
||||
_buildDayCheckboxes(context, state.selectedDays,
|
||||
isEdit: isEdit),
|
||||
const SizedBox(height: 16),
|
||||
_buildFunctionSwitch(context, state.functionOn, isEdit),
|
||||
],
|
||||
@ -188,9 +192,9 @@ class GarageDoorDialogHelper {
|
||||
|
||||
static List<bool> _convertDaysStringToBooleans(List<String> selectedDays) {
|
||||
final daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
List<bool> daysBoolean = List.filled(7, false);
|
||||
final daysBoolean = List<bool>.filled(7, false);
|
||||
|
||||
for (int i = 0; i < daysOfWeek.length; i++) {
|
||||
for (var i = 0; i < daysOfWeek.length; i++) {
|
||||
if (selectedDays.contains(daysOfWeek[i])) {
|
||||
daysBoolean[i] = true;
|
||||
}
|
||||
@ -199,7 +203,9 @@ class GarageDoorDialogHelper {
|
||||
return daysBoolean;
|
||||
}
|
||||
|
||||
static Widget _buildDayCheckboxes(BuildContext context, List<bool> selectedDays, {bool? isEdit}) {
|
||||
static Widget _buildDayCheckboxes(
|
||||
BuildContext context, List<bool> selectedDays,
|
||||
{bool? isEdit}) {
|
||||
final dayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
|
||||
return Row(
|
||||
@ -209,7 +215,9 @@ class GarageDoorDialogHelper {
|
||||
Checkbox(
|
||||
value: selectedDays[index],
|
||||
onChanged: (bool? value) {
|
||||
context.read<GarageDoorBloc>().add(UpdateSelectedDayEvent(index, value!));
|
||||
context
|
||||
.read<GarageDoorBloc>()
|
||||
.add(UpdateSelectedDayEvent(index, value!));
|
||||
},
|
||||
),
|
||||
Text(dayLabels[index]),
|
||||
@ -219,19 +227,23 @@ class GarageDoorDialogHelper {
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _buildFunctionSwitch(BuildContext context, bool isOn, bool? isEdit) {
|
||||
static Widget _buildFunctionSwitch(
|
||||
BuildContext context, bool isOn, bool? isEdit) {
|
||||
return Row(
|
||||
children: [
|
||||
Text(
|
||||
'Function:',
|
||||
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.grayColor),
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.grayColor),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Radio<bool>(
|
||||
value: true,
|
||||
groupValue: isOn,
|
||||
onChanged: (bool? value) {
|
||||
context.read<GarageDoorBloc>().add(const UpdateFunctionOnEvent(functionOn: true));
|
||||
context
|
||||
.read<GarageDoorBloc>()
|
||||
.add(const UpdateFunctionOnEvent(functionOn: true));
|
||||
},
|
||||
),
|
||||
const Text('On'),
|
||||
@ -240,7 +252,9 @@ class GarageDoorDialogHelper {
|
||||
value: false,
|
||||
groupValue: isOn,
|
||||
onChanged: (bool? value) {
|
||||
context.read<GarageDoorBloc>().add(const UpdateFunctionOnEvent(functionOn: false));
|
||||
context
|
||||
.read<GarageDoorBloc>()
|
||||
.add(const UpdateFunctionOnEvent(functionOn: false));
|
||||
},
|
||||
),
|
||||
const Text('Off'),
|
||||
@ -297,13 +311,17 @@ class GarageDoorDialogHelper {
|
||||
alertBody: TimeOutAlarmDialogBody(bloc),
|
||||
title: 'Time Out Alarm',
|
||||
onConfirm: () {
|
||||
final updatedState = context.read<GarageDoorBloc>().state;
|
||||
if (updatedState is GarageDoorLoadedState) {
|
||||
final updatedState =
|
||||
context.read<GarageDoorBloc>().state;
|
||||
if (updatedState
|
||||
is GarageDoorLoadedState) {
|
||||
context.read<GarageDoorBloc>().add(
|
||||
GarageDoorControlEvent(
|
||||
deviceId: updatedState.status.uuid,
|
||||
deviceId:
|
||||
updatedState.status.uuid,
|
||||
code: 'countdown_alarm',
|
||||
value: updatedState.status.countdownAlarm,
|
||||
value: updatedState
|
||||
.status.countdownAlarm,
|
||||
),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
@ -311,8 +329,11 @@ class GarageDoorDialogHelper {
|
||||
});
|
||||
},
|
||||
child: ToggleWidget(
|
||||
icon: "-1",
|
||||
value: state.status.doorState1 == "close_time_alarm" ? false : true,
|
||||
icon: '-1',
|
||||
value: state.status.doorState1 ==
|
||||
'close_time_alarm'
|
||||
? false
|
||||
: true,
|
||||
code: 'door_state_1',
|
||||
deviceId: bloc.deviceId,
|
||||
label: 'Alarm when door is open',
|
||||
@ -321,9 +342,10 @@ class GarageDoorDialogHelper {
|
||||
GarageDoorControlEvent(
|
||||
deviceId: bloc.deviceId,
|
||||
code: 'door_state_1',
|
||||
value: state.status.doorState1 == "close_time_alarm"
|
||||
? "unclosed_time"
|
||||
: "close_time_alarm",
|
||||
value: state.status.doorState1 ==
|
||||
'close_time_alarm'
|
||||
? 'unclosed_time'
|
||||
: 'close_time_alarm',
|
||||
),
|
||||
);
|
||||
}),
|
||||
@ -348,13 +370,17 @@ class GarageDoorDialogHelper {
|
||||
),
|
||||
title: 'Opening and Closing Time',
|
||||
onConfirm: () {
|
||||
final updatedState = context.read<GarageDoorBloc>().state;
|
||||
if (updatedState is GarageDoorLoadedState) {
|
||||
final updatedState =
|
||||
context.read<GarageDoorBloc>().state;
|
||||
if (updatedState
|
||||
is GarageDoorLoadedState) {
|
||||
context.read<GarageDoorBloc>().add(
|
||||
GarageDoorControlEvent(
|
||||
deviceId: updatedState.status.uuid,
|
||||
deviceId:
|
||||
updatedState.status.uuid,
|
||||
code: 'tr_timecon',
|
||||
value: updatedState.status.trTimeCon,
|
||||
value: updatedState
|
||||
.status.trTimeCon,
|
||||
),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
|
||||
@ -39,9 +39,9 @@ class GarageDoorStatusModel {
|
||||
late String doorControl1;
|
||||
late bool voiceControl1;
|
||||
late String doorState1;
|
||||
List<ScheduleModel> schedules = []; // Initialize schedules
|
||||
final schedules = <ScheduleModel>[]; // Initialize schedules
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false;
|
||||
|
||||
@ -11,10 +11,11 @@ import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class GarageDoorBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class GarageDoorBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final List<String> deviceIds;
|
||||
|
||||
const GarageDoorBatchControlView({Key? key, required this.deviceIds}) : super(key: key);
|
||||
const GarageDoorBatchControlView({super.key, required this.deviceIds});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -37,7 +38,8 @@ class GarageDoorBatchControlView extends StatelessWidget with HelperResponsiveLa
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, GarageDoorStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, GarageDoorStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||
@ -8,7 +7,8 @@ class OpeningAndClosingTimeDialogBody extends StatefulWidget {
|
||||
final ValueChanged<int> onDurationChanged;
|
||||
final GarageDoorBloc bloc;
|
||||
|
||||
OpeningAndClosingTimeDialogBody({
|
||||
const OpeningAndClosingTimeDialogBody({
|
||||
super.key,
|
||||
required this.onDurationChanged,
|
||||
required this.bloc,
|
||||
});
|
||||
|
||||
@ -26,7 +26,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
Table(
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.graysColor,
|
||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
|
||||
),
|
||||
children: [
|
||||
TableRow(
|
||||
@ -50,17 +51,21 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
BlocBuilder<GarageDoorBloc, GarageDoorState>(
|
||||
builder: (context, state) {
|
||||
if (state is ScheduleGarageLoadingState) {
|
||||
return const SizedBox(height: 200, child: Center(child: CircularProgressIndicator()));
|
||||
return const SizedBox(
|
||||
height: 200,
|
||||
child: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
if (state is GarageDoorLoadedState && state.status.schedules?.isEmpty == true) {
|
||||
if (state is GarageDoorLoadedState &&
|
||||
state.status.schedules?.isEmpty == true) {
|
||||
return _buildEmptyState(context);
|
||||
} else if (state is GarageDoorLoadedState) {
|
||||
return Container(
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ColorsManager.graysColor),
|
||||
borderRadius:
|
||||
const BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(20),
|
||||
bottomRight: Radius.circular(20)),
|
||||
),
|
||||
child: _buildTableBody(state, context));
|
||||
}
|
||||
@ -78,7 +83,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ColorsManager.graysColor),
|
||||
borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
@ -112,7 +118,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
children: [
|
||||
if (state.status.schedules != null)
|
||||
for (int i = 0; i < state.status.schedules!.length; i++)
|
||||
_buildScheduleRow(state.status.schedules![i], i, context, state),
|
||||
_buildScheduleRow(
|
||||
state.status.schedules![i], i, context, state),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -134,7 +141,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
TableRow _buildScheduleRow(ScheduleModel schedule, int index, BuildContext context, GarageDoorLoadedState state) {
|
||||
TableRow _buildScheduleRow(ScheduleModel schedule, int index,
|
||||
BuildContext context, GarageDoorLoadedState state) {
|
||||
return TableRow(
|
||||
children: [
|
||||
Center(
|
||||
@ -152,7 +160,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: schedule.enable
|
||||
? const Icon(Icons.radio_button_checked, color: ColorsManager.blueColor)
|
||||
? const Icon(Icons.radio_button_checked,
|
||||
color: ColorsManager.blueColor)
|
||||
: const Icon(
|
||||
Icons.radio_button_unchecked,
|
||||
color: ColorsManager.grayColor,
|
||||
@ -160,7 +169,9 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(child: Text(_getSelectedDays(ScheduleModel.parseSelectedDays(schedule.days)))),
|
||||
Center(
|
||||
child: Text(_getSelectedDays(
|
||||
ScheduleModel.parseSelectedDays(schedule.days)))),
|
||||
Center(child: Text(formatIsoStringToTime(schedule.time, context))),
|
||||
Center(child: Text(schedule.function.value ? 'On' : 'Off')),
|
||||
Center(
|
||||
@ -170,18 +181,24 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(padding: EdgeInsets.zero),
|
||||
onPressed: () {
|
||||
GarageDoorDialogHelper.showAddGarageDoorScheduleDialog(context,
|
||||
schedule: schedule, index: index, isEdit: true);
|
||||
GarageDoorDialogHelper.showAddGarageDoorScheduleDialog(
|
||||
context,
|
||||
schedule: schedule,
|
||||
index: index,
|
||||
isEdit: true);
|
||||
},
|
||||
child: Text(
|
||||
'Edit',
|
||||
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blueColor),
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.blueColor),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(padding: EdgeInsets.zero),
|
||||
onPressed: () {
|
||||
context.read<GarageDoorBloc>().add(DeleteGarageDoorScheduleEvent(
|
||||
context
|
||||
.read<GarageDoorBloc>()
|
||||
.add(DeleteGarageDoorScheduleEvent(
|
||||
index: index,
|
||||
scheduleId: schedule.scheduleId,
|
||||
deviceId: state.status.uuid,
|
||||
@ -189,7 +206,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
},
|
||||
child: Text(
|
||||
'Delete',
|
||||
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blueColor),
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.blueColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -201,8 +219,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
|
||||
|
||||
String _getSelectedDays(List<bool> selectedDays) {
|
||||
final days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
List<String> selectedDaysStr = [];
|
||||
for (int i = 0; i < selectedDays.length; i++) {
|
||||
final selectedDaysStr = <String>[];
|
||||
for (var i = 0; i < selectedDays.length; i++) {
|
||||
if (selectedDays[i]) {
|
||||
selectedDaysStr.add(days[i]);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class ScheduleGarageManagementUI extends StatelessWidget {
|
||||
padding: 2,
|
||||
backgroundColor: ColorsManager.graysColor,
|
||||
borderRadius: 15,
|
||||
onPressed: () => onAddSchedule(),
|
||||
onPressed: onAddSchedule,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.add, color: ColorsManager.primaryColor),
|
||||
|
||||
@ -35,7 +35,8 @@ class ScheduleGarageDoorModeSelector extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRadioTile(BuildContext context, String label, ScheduleModes mode, GarageDoorLoadedState state) {
|
||||
Widget _buildRadioTile(BuildContext context, String label, ScheduleModes mode,
|
||||
GarageDoorLoadedState state) {
|
||||
return Flexible(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
|
||||
@ -4,7 +4,8 @@ class SecondsPicker extends StatefulWidget {
|
||||
final int initialSeconds;
|
||||
final ValueChanged<int> onSecondsChanged;
|
||||
|
||||
SecondsPicker({
|
||||
const SecondsPicker({
|
||||
super.key,
|
||||
required this.initialSeconds,
|
||||
required this.onSecondsChanged,
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_
|
||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||
|
||||
class TimeOutAlarmDialogBody extends StatefulWidget {
|
||||
TimeOutAlarmDialogBody(this.bloc);
|
||||
const TimeOutAlarmDialogBody(this.bloc, {super.key});
|
||||
final GarageDoorBloc bloc;
|
||||
|
||||
@override
|
||||
|
||||
@ -16,10 +16,12 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
|
||||
on<GateWayFactoryReset>(_onFactoryReset);
|
||||
}
|
||||
|
||||
FutureOr<void> _getGatWayById(GatWayById event, Emitter<GateWayState> emit) async {
|
||||
FutureOr<void> _getGatWayById(
|
||||
GatWayById event, Emitter<GateWayState> emit) async {
|
||||
emit(GatewayLoadingState());
|
||||
try {
|
||||
List<DeviceModel> devicesList = await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
|
||||
final devicesList =
|
||||
await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
|
||||
|
||||
emit(UpdateGatewayState(list: devicesList));
|
||||
} catch (e) {
|
||||
@ -28,7 +30,8 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onFactoryReset(GateWayFactoryReset event, Emitter<GateWayState> emit) async {
|
||||
FutureOr<void> _onFactoryReset(
|
||||
GateWayFactoryReset event, Emitter<GateWayState> emit) async {
|
||||
emit(GatewayLoadingState());
|
||||
try {
|
||||
final response = await DevicesManagementApi().factoryReset(
|
||||
|
||||
@ -6,7 +6,8 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class GatewayBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class GatewayBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const GatewayBatchControlView({super.key, required this.gatewayIds});
|
||||
|
||||
final List<String> gatewayIds;
|
||||
@ -38,7 +39,8 @@ class GatewayBatchControlView extends StatelessWidget with HelperResponsiveLayou
|
||||
context.read<GateWayBloc>().add(
|
||||
GateWayFactoryReset(
|
||||
deviceId: gatewayIds.first,
|
||||
factoryReset: FactoryResetModel(devicesUuid: gatewayIds),
|
||||
factoryReset:
|
||||
FactoryResetModel(devicesUuid: gatewayIds),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -37,21 +37,21 @@ class GateWayControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"Bluetooth Devices:",
|
||||
'Bluetooth Devices:',
|
||||
style: context.textTheme.bodyMedium!.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
"No devices found",
|
||||
'No devices found',
|
||||
style: context.textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
Text(
|
||||
"ZigBee Devices:",
|
||||
'ZigBee Devices:',
|
||||
style: context.textTheme.bodyMedium!.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
),
|
||||
|
||||
@ -159,17 +159,15 @@ class MainDoorSensorBloc
|
||||
}
|
||||
}
|
||||
|
||||
_listenToChanges(deviceId) {
|
||||
void _listenToChanges(deviceId) {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
Stream<DatabaseEvent> stream = ref.onValue;
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
final stream = ref.onValue;
|
||||
|
||||
stream.listen((DatabaseEvent event) {
|
||||
Map<dynamic, dynamic> usersMap =
|
||||
event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
usersMap['status'].forEach((element) {
|
||||
statusList
|
||||
.add(Status(code: element['code'], value: element['value']));
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/main_door_sensor/models/main_door_status_model.dart';
|
||||
|
||||
import '../../all_devices/models/factory_reset_model.dart';
|
||||
|
||||
class MainDoorSensorEvent extends Equatable {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
@ -75,7 +74,7 @@ class MainDoorSensorFactoryReset extends MainDoorSensorEvent {
|
||||
|
||||
class StatusUpdated extends MainDoorSensorEvent {
|
||||
final MainDoorSensorStatusModel deviceStatus;
|
||||
StatusUpdated(this.deviceStatus);
|
||||
StatusUpdated(this.deviceStatus);
|
||||
@override
|
||||
List<Object> get props => [deviceStatus];
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ class MainDoorSensorStatusModel {
|
||||
});
|
||||
|
||||
factory MainDoorSensorStatusModel.fromJson(String id, List<Status> jsonList) {
|
||||
late bool doorContactState = false;
|
||||
late int batteryPercentage = 0;
|
||||
late var doorContactState = false;
|
||||
late var batteryPercentage = 0;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'doorcontact_state':
|
||||
doorContactState = status.value ?? false;
|
||||
|
||||
@ -12,7 +12,8 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class MainDoorSensorControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const MainDoorSensorControlView({super.key, required this.device});
|
||||
|
||||
final AllDevicesModel device;
|
||||
@ -20,10 +21,12 @@ class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLay
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => MainDoorSensorBloc()..add(MainDoorSensorFetchDeviceEvent(device.uuid!)),
|
||||
create: (context) => MainDoorSensorBloc()
|
||||
..add(MainDoorSensorFetchDeviceEvent(device.uuid!)),
|
||||
child: BlocBuilder<MainDoorSensorBloc, MainDoorSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is MainDoorSensorLoadingState || state is MainDoorSensorReportsLoadingState) {
|
||||
if (state is MainDoorSensorLoadingState ||
|
||||
state is MainDoorSensorReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is MainDoorSensorDeviceStatusLoaded) {
|
||||
return _buildStatusControls(context, state.status);
|
||||
@ -32,12 +35,15 @@ class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLay
|
||||
report: state.deviceReport,
|
||||
onRowTap: (index) {},
|
||||
onClose: () {
|
||||
context.read<MainDoorSensorBloc>().add(MainDoorSensorFetchDeviceEvent(device.uuid!));
|
||||
context
|
||||
.read<MainDoorSensorBloc>()
|
||||
.add(MainDoorSensorFetchDeviceEvent(device.uuid!));
|
||||
},
|
||||
hideValueShowDescription: true,
|
||||
mainDoorSensor: true,
|
||||
);
|
||||
} else if (state is MainDoorSensorFailedState || state is MainDoorSensorBatchFailedState) {
|
||||
} else if (state is MainDoorSensorFailedState ||
|
||||
state is MainDoorSensorBatchFailedState) {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@ -46,7 +52,8 @@ class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLay
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, MainDoorSensorStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, MainDoorSensorStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -71,7 +78,9 @@ class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLay
|
||||
icon: Assets.openCloseDoor,
|
||||
onTap: () {},
|
||||
status: status.doorContactState,
|
||||
textColor: status.doorContactState ? ColorsManager.red : ColorsManager.blackColor,
|
||||
textColor: status.doorContactState
|
||||
? ColorsManager.red
|
||||
: ColorsManager.blackColor,
|
||||
paddingAmount: 8,
|
||||
),
|
||||
IconNameStatusContainer(
|
||||
@ -79,7 +88,9 @@ class MainDoorSensorControlView extends StatelessWidget with HelperResponsiveLay
|
||||
name: 'Open/Close\nRecord',
|
||||
icon: Assets.openCloseRecords,
|
||||
onTap: () {
|
||||
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
|
||||
final from = DateTime.now()
|
||||
.subtract(const Duration(days: 30))
|
||||
.millisecondsSinceEpoch;
|
||||
final to = DateTime.now().millisecondsSinceEpoch;
|
||||
context.read<MainDoorSensorBloc>().add(
|
||||
MainDoorSensorReportsEvent(
|
||||
|
||||
@ -27,7 +27,8 @@ class MainDoorSensorBatchView extends StatelessWidget {
|
||||
BlocProvider.of<MainDoorSensorBloc>(innerContext).add(
|
||||
MainDoorSensorFactoryReset(
|
||||
deviceId: devicesIds.first,
|
||||
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
|
||||
factoryReset:
|
||||
FactoryResetModel(devicesUuid: devicesIds),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -53,7 +53,7 @@ class _NotificationDialogState extends State<NotificationDialog> {
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(1),
|
||||
padding: const EdgeInsets.all(1),
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.grey,
|
||||
|
||||
@ -39,9 +39,11 @@ class OneGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(OneGangGlassSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(event.deviceId, emit);
|
||||
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||
deviceStatus =
|
||||
OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(OneGangGlassSwitchError(e.toString()));
|
||||
@ -62,7 +64,7 @@ class OneGangGlassSwitchBloc
|
||||
|
||||
final statusList = <Status>[];
|
||||
if (data['status'] != null) {
|
||||
for (var element in data['status']) {
|
||||
for (final element in data['status']) {
|
||||
statusList.add(
|
||||
Status(
|
||||
code: element['code'].toString(),
|
||||
@ -72,7 +74,8 @@ class OneGangGlassSwitchBloc
|
||||
}
|
||||
}
|
||||
if (statusList.isNotEmpty) {
|
||||
final newStatus = OneGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
final newStatus =
|
||||
OneGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
if (newStatus != deviceStatus) {
|
||||
deviceStatus = newStatus;
|
||||
if (!isClosed) {
|
||||
@ -140,9 +143,10 @@ class OneGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(OneGangGlassSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus =
|
||||
OneGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus = OneGangGlassStatusModel.fromJson(
|
||||
event.deviceIds.first, status.status);
|
||||
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(OneGangGlassSwitchError(e.toString()));
|
||||
|
||||
@ -15,7 +15,7 @@ class OneGangGlassStatusModel {
|
||||
late bool switch1;
|
||||
late int countDown;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false;
|
||||
@ -46,5 +46,6 @@ class OneGangGlassStatusModel {
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'OneGangGlassStatusModel(uuid: $uuid, switch1: $switch1, countDown: $countDown)';
|
||||
String toString() =>
|
||||
'OneGangGlassStatusModel(uuid: $uuid, switch1: $switch1, countDown: $countDown)';
|
||||
}
|
||||
|
||||
@ -8,16 +8,19 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class OneGangGlassSwitchBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class OneGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final List<String> deviceIds;
|
||||
|
||||
const OneGangGlassSwitchBatchControlView({required this.deviceIds, super.key});
|
||||
const OneGangGlassSwitchBatchControlView(
|
||||
{required this.deviceIds, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => OneGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(OneGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
create: (context) =>
|
||||
OneGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(OneGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
child: BlocBuilder<OneGangGlassSwitchBloc, OneGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is OneGangGlassSwitchLoading) {
|
||||
@ -34,7 +37,8 @@ class OneGangGlassSwitchBatchControlView extends StatelessWidget with HelperResp
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, OneGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, OneGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
|
||||
@ -7,7 +7,8 @@ import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class OneGangGlassSwitchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class OneGangGlassSwitchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final String deviceId;
|
||||
|
||||
const OneGangGlassSwitchControlView({required this.deviceId, super.key});
|
||||
@ -16,7 +17,8 @@ class OneGangGlassSwitchControlView extends StatelessWidget with HelperResponsiv
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
OneGangGlassSwitchBlocFactory.create(deviceId: deviceId)..add(OneGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
OneGangGlassSwitchBlocFactory.create(deviceId: deviceId)
|
||||
..add(OneGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
child: BlocBuilder<OneGangGlassSwitchBloc, OneGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is OneGangGlassSwitchLoading) {
|
||||
@ -33,7 +35,8 @@ class OneGangGlassSwitchControlView extends StatelessWidget with HelperResponsiv
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, OneGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, OneGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -56,7 +59,7 @@ class OneGangGlassSwitchControlView extends StatelessWidget with HelperResponsiv
|
||||
value: status.switch1,
|
||||
code: 'switch_1',
|
||||
deviceId: deviceId,
|
||||
label: "Wall Light",
|
||||
label: 'Wall Light',
|
||||
onChange: (value) {
|
||||
context.read<OneGangGlassSwitchBloc>().add(
|
||||
OneGangGlassSwitchControl(
|
||||
|
||||
@ -10,7 +10,8 @@ import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
||||
import 'package:syncrow_web/services/control_device_service.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
|
||||
class WallLightSwitchBloc extends Bloc<WallLightSwitchEvent, WallLightSwitchState> {
|
||||
class WallLightSwitchBloc
|
||||
extends Bloc<WallLightSwitchEvent, WallLightSwitchState> {
|
||||
late WallLightStatusModel deviceStatus;
|
||||
final String deviceId;
|
||||
final ControlDeviceService controlDeviceService;
|
||||
@ -35,9 +36,11 @@ class WallLightSwitchBloc extends Bloc<WallLightSwitchEvent, WallLightSwitchStat
|
||||
) async {
|
||||
emit(WallLightSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(event.deviceId, emit);
|
||||
deviceStatus = WallLightStatusModel.fromJson(event.deviceId, status.status);
|
||||
deviceStatus =
|
||||
WallLightStatusModel.fromJson(event.deviceId, status.status);
|
||||
emit(WallLightSwitchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(WallLightSwitchError(e.toString()));
|
||||
@ -58,7 +61,7 @@ class WallLightSwitchBloc extends Bloc<WallLightSwitchEvent, WallLightSwitchStat
|
||||
|
||||
final statusList = <Status>[];
|
||||
if (data['status'] != null) {
|
||||
for (var element in data['status']) {
|
||||
for (final element in data['status']) {
|
||||
statusList.add(
|
||||
Status(
|
||||
code: element['code'].toString(),
|
||||
@ -136,7 +139,8 @@ class WallLightSwitchBloc extends Bloc<WallLightSwitchEvent, WallLightSwitchStat
|
||||
) async {
|
||||
emit(WallLightSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus =
|
||||
WallLightStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
emit(WallLightSwitchStatusLoaded(deviceStatus));
|
||||
|
||||
@ -15,7 +15,7 @@ class WallLightStatusModel {
|
||||
late bool switch1;
|
||||
late int countDown;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false;
|
||||
|
||||
@ -10,7 +10,8 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class WallLightBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class WallLightBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const WallLightBatchControlView({super.key, required this.deviceIds});
|
||||
|
||||
final List<String> deviceIds;
|
||||
@ -18,15 +19,17 @@ class WallLightBatchControlView extends StatelessWidget with HelperResponsiveLay
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => WallLightSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(WallLightSwitchFetchBatchEvent(deviceIds)),
|
||||
create: (context) =>
|
||||
WallLightSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(WallLightSwitchFetchBatchEvent(deviceIds)),
|
||||
child: BlocBuilder<WallLightSwitchBloc, WallLightSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is WallLightSwitchLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is WallLightSwitchStatusLoaded) {
|
||||
return _buildStatusControls(context, state.status);
|
||||
} else if (state is WallLightSwitchError || state is WallLightSwitchControlError) {
|
||||
} else if (state is WallLightSwitchError ||
|
||||
state is WallLightSwitchControlError) {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@ -36,7 +39,8 @@ class WallLightBatchControlView extends StatelessWidget with HelperResponsiveLay
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, WallLightStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, WallLightStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -78,7 +82,8 @@ class WallLightBatchControlView extends StatelessWidget with HelperResponsiveLay
|
||||
FactoryResetWidget(
|
||||
callFactoryReset: () {
|
||||
context.read<WallLightSwitchBloc>().add(WallLightFactoryReset(
|
||||
deviceId: status.uuid, factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
|
||||
deviceId: status.uuid,
|
||||
factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@ -215,33 +215,46 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
SmartPowerFetchDeviceEvent event, Emitter<SmartPowerState> emit) async {
|
||||
emit(SmartPowerLoading());
|
||||
try {
|
||||
var status =
|
||||
final status =
|
||||
await DevicesManagementApi().getPowerClampInfo(event.deviceId);
|
||||
deviceStatus = PowerClampModel.fromJson(status as Map<String, Object?>? ??{});
|
||||
deviceStatus =
|
||||
PowerClampModel.fromJson(status as Map<String, Object?>? ?? {});
|
||||
final phaseADataPoints = deviceStatus.status.phaseA.dataPoints;
|
||||
final phaseBDataPoints = deviceStatus.status.phaseB.dataPoints;
|
||||
final phaseCDataPoints = deviceStatus.status.phaseC.dataPoints;
|
||||
phaseData = [
|
||||
{
|
||||
'name': 'Phase A',
|
||||
'voltage': '${(phaseADataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseADataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseADataPoints.elementAtOrNull(2)?.value??'N/A'} W',
|
||||
'powerFactor': '${phaseADataPoints.elementAtOrNull(3)?.value??'N/A'}',
|
||||
'voltage':
|
||||
'${(phaseADataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current':
|
||||
'${(phaseADataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower':
|
||||
'${phaseADataPoints.elementAtOrNull(2)?.value ?? 'N/A'} W',
|
||||
'powerFactor':
|
||||
'${phaseADataPoints.elementAtOrNull(3)?.value ?? 'N/A'}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase B',
|
||||
'voltage': '${(phaseBDataPoints .elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseBDataPoints .elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseBDataPoints.elementAtOrNull(2)?.value??'N/A'} W',
|
||||
'powerFactor': '${phaseBDataPoints.elementAtOrNull(3)?.value??'N/A'}',
|
||||
'voltage':
|
||||
'${(phaseBDataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current':
|
||||
'${(phaseBDataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower':
|
||||
'${phaseBDataPoints.elementAtOrNull(2)?.value ?? 'N/A'} W',
|
||||
'powerFactor':
|
||||
'${phaseBDataPoints.elementAtOrNull(3)?.value ?? 'N/A'}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase C',
|
||||
'voltage': '${(phaseCDataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseCDataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseCDataPoints.elementAtOrNull(2)?.value ?? 'N/A'} W',
|
||||
'powerFactor': '${phaseCDataPoints.elementAtOrNull(3)?.value ?? 'N/A'}',
|
||||
'voltage':
|
||||
'${(phaseCDataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current':
|
||||
'${(phaseCDataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower':
|
||||
'${phaseCDataPoints.elementAtOrNull(2)?.value ?? 'N/A'} W',
|
||||
'powerFactor':
|
||||
'${phaseCDataPoints.elementAtOrNull(3)?.value ?? 'N/A'}',
|
||||
},
|
||||
];
|
||||
emit(GetDeviceStatus());
|
||||
@ -305,8 +318,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
try {
|
||||
final response =
|
||||
await DevicesManagementApi().getPowerStatus(event.devicesIds);
|
||||
PowerClampBatchModel deviceStatus =
|
||||
PowerClampBatchModel.fromJson(response);
|
||||
final deviceStatus = PowerClampBatchModel.fromJson(response);
|
||||
|
||||
emit(SmartPowerLoadBatchControll(deviceStatus));
|
||||
} catch (e) {
|
||||
@ -417,15 +429,15 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
}
|
||||
|
||||
Future<DateTime?> selectMonthAndYear(BuildContext context) async {
|
||||
int selectedYear = DateTime.now().year;
|
||||
int selectedMonth = DateTime.now().month;
|
||||
var selectedYear = DateTime.now().year;
|
||||
var selectedMonth = DateTime.now().month;
|
||||
|
||||
FixedExtentScrollController yearController =
|
||||
final yearController =
|
||||
FixedExtentScrollController(initialItem: selectedYear - 1905);
|
||||
FixedExtentScrollController monthController =
|
||||
final monthController =
|
||||
FixedExtentScrollController(initialItem: selectedMonth - 1);
|
||||
|
||||
return await showDialog<DateTime>(
|
||||
return showDialog<DateTime>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Column(
|
||||
@ -537,11 +549,11 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
}
|
||||
|
||||
Future<DateTime?> selectYear(BuildContext context) async {
|
||||
int selectedYear = DateTime.now().year;
|
||||
FixedExtentScrollController yearController =
|
||||
var selectedYear = DateTime.now().year;
|
||||
final yearController =
|
||||
FixedExtentScrollController(initialItem: selectedYear - 1905);
|
||||
|
||||
return await showDialog<DateTime>(
|
||||
return showDialog<DateTime>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Column(
|
||||
@ -622,9 +634,9 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
Future<DateTime?> dayMonthYearPicker({
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
DateTime selectedDate = DateTime.now();
|
||||
var selectedDate = DateTime.now();
|
||||
|
||||
return await showDialog<DateTime>(
|
||||
return showDialog<DateTime>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Column(
|
||||
@ -686,7 +698,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
|
||||
String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now());
|
||||
|
||||
void checkDayMonthYearSelected(
|
||||
Future<void> checkDayMonthYearSelected(
|
||||
SelectDateEvent event, Emitter<SmartPowerState> emit) async {
|
||||
Future<DateTime?> Function(BuildContext context)? dateSelector;
|
||||
String dateFormat;
|
||||
@ -698,15 +710,11 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
dateFormat = 'yyyy/MM/dd';
|
||||
break;
|
||||
case 1:
|
||||
dateSelector = (context) {
|
||||
return selectMonthAndYear(context);
|
||||
};
|
||||
dateSelector = selectMonthAndYear;
|
||||
dateFormat = 'yyyy-MM';
|
||||
break;
|
||||
case 2:
|
||||
dateSelector = (context) {
|
||||
return selectYear(context);
|
||||
};
|
||||
dateSelector = selectYear;
|
||||
dateFormat = 'yyyy';
|
||||
break;
|
||||
default:
|
||||
@ -743,7 +751,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
.toList();
|
||||
} else if (event.viewType == 'Month') {
|
||||
formattedDate =
|
||||
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}";
|
||||
'${event.selectedDate.year}-${getMonthShortName(event.selectedDate.month)}';
|
||||
|
||||
filteredRecords = record
|
||||
.where((record) =>
|
||||
@ -752,7 +760,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
.toList();
|
||||
} else if (event.viewType == 'Day') {
|
||||
formattedDate =
|
||||
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}";
|
||||
'${event.selectedDate.year}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}';
|
||||
|
||||
filteredRecords = record
|
||||
.where((record) =>
|
||||
@ -784,11 +792,11 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
|
||||
String endChartDate = '';
|
||||
|
||||
void selectDateRange() async {
|
||||
DateTime startDate = dateTime!;
|
||||
DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1)
|
||||
Future<void> selectDateRange() async {
|
||||
final startDate = dateTime!;
|
||||
final endDate = DateTime(startDate.year, startDate.month + 1, 1)
|
||||
.subtract(const Duration(days: 1));
|
||||
String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
|
||||
final formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
|
||||
endChartDate = ' - $formattedEndDate';
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,16 +95,18 @@ class FilterRecordsByDateEvent extends SmartPowerEvent {
|
||||
class FetchPowerClampBatchStatusEvent extends SmartPowerEvent {
|
||||
final List<String> deviceIds;
|
||||
|
||||
FetchPowerClampBatchStatusEvent(this.deviceIds);
|
||||
FetchPowerClampBatchStatusEvent(this.deviceIds);
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceIds];
|
||||
}class PowerBatchControlEvent extends SmartPowerEvent {
|
||||
}
|
||||
|
||||
class PowerBatchControlEvent extends SmartPowerEvent {
|
||||
final List<String> deviceIds;
|
||||
final String code;
|
||||
final dynamic value;
|
||||
|
||||
PowerBatchControlEvent({
|
||||
PowerBatchControlEvent({
|
||||
required this.deviceIds,
|
||||
required this.code,
|
||||
required this.value,
|
||||
@ -112,4 +114,4 @@ class FetchPowerClampBatchStatusEvent extends SmartPowerEvent {
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceIds, code, value];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
class EventDevice {
|
||||
final String? code;
|
||||
final DateTime? eventTime;
|
||||
@ -12,7 +11,7 @@ class EventDevice {
|
||||
|
||||
EventDevice.fromJson(Map<String, dynamic> json)
|
||||
: code = json['code'] as String?,
|
||||
eventTime = json['eventTime'] ,
|
||||
eventTime = json['eventTime'],
|
||||
value = json['value'] as String?;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
|
||||
@ -19,10 +19,10 @@ class PowerClampBatchModel extends PowerClampModel1 {
|
||||
});
|
||||
|
||||
factory PowerClampBatchModel.fromJson(Map<String, dynamic> json) {
|
||||
String productUuid = json['productUuid'] ?? '';
|
||||
String productType = json['productType'] ?? '';
|
||||
final String productUuid = json['productUuid'] ?? '';
|
||||
final String productType = json['productType'] ?? '';
|
||||
|
||||
List<Status> statusList = [];
|
||||
var statusList = <Status>[];
|
||||
if (json['status'] != null && json['status'] is List) {
|
||||
statusList =
|
||||
(json['status'] as List).map((e) => Status.fromJson(e)).toList();
|
||||
|
||||
@ -16,7 +16,8 @@ class PowerClampModel {
|
||||
return PowerClampModel(
|
||||
productUuid: json['productUuid'] as String? ?? '',
|
||||
productType: json['productType'] as String? ?? '',
|
||||
status: PowerStatus.fromJson(json['status'] as Map<String, dynamic>? ?? {}),
|
||||
status:
|
||||
PowerStatus.fromJson(json['status'] as Map<String, dynamic>? ?? {}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,8 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
class PhaseWidget extends StatefulWidget {
|
||||
final List<Map<String, dynamic>> phaseData;
|
||||
|
||||
PhaseWidget({
|
||||
const PhaseWidget({
|
||||
super.key,
|
||||
required this.phaseData,
|
||||
});
|
||||
@override
|
||||
@ -19,7 +20,7 @@ class _PhaseWidgetState extends State<PhaseWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(height: 10),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: List.generate(widget.phaseData.length, (index) {
|
||||
return InkWell(
|
||||
@ -43,27 +44,28 @@ class _PhaseWidgetState extends State<PhaseWidget> {
|
||||
);
|
||||
}),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
_selectedPhaseIndex == 0
|
||||
? phase(
|
||||
totalActive: widget.phaseData[0]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[0]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[0]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[0]['voltage'] ?? '0',
|
||||
)
|
||||
: _selectedPhaseIndex == 1
|
||||
? phase(
|
||||
totalActive: widget.phaseData[1]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[1]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[1]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[1]['voltage'] ?? '0',
|
||||
)
|
||||
: phase(
|
||||
totalActive: widget.phaseData[2]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[2]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[2]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[2]['voltage'] ?? '0',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (_selectedPhaseIndex == 0)
|
||||
phase(
|
||||
totalActive: widget.phaseData[0]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[0]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[0]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[0]['voltage'] ?? '0',
|
||||
)
|
||||
else
|
||||
_selectedPhaseIndex == 1
|
||||
? phase(
|
||||
totalActive: widget.phaseData[1]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[1]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[1]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[1]['voltage'] ?? '0',
|
||||
)
|
||||
: phase(
|
||||
totalActive: widget.phaseData[2]['activePower'] ?? '0',
|
||||
totalCurrent: widget.phaseData[2]['current'] ?? '0',
|
||||
totalFactor: widget.phaseData[2]['powerFactor'] ?? '0',
|
||||
totalVoltage: widget.phaseData[2]['voltage'] ?? '0',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
return ColoredBox(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: Column(
|
||||
children: [
|
||||
@ -146,7 +146,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
showTitles: false,
|
||||
reservedSize: 70,
|
||||
getTitlesWidget: (value, meta) {
|
||||
int index = value.toInt();
|
||||
final index = value.toInt();
|
||||
if (index >= 0 && index < _chartData.length) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@ -169,14 +169,14 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
verticalInterval: 1,
|
||||
getDrawingVerticalLine: (value) {
|
||||
return FlLine(
|
||||
color: Colors.grey.withOpacity(0.2),
|
||||
color: Colors.grey.withValues(alpha: 0.2),
|
||||
dashArray: [8, 8],
|
||||
strokeWidth: 1,
|
||||
);
|
||||
},
|
||||
getDrawingHorizontalLine: (value) {
|
||||
return FlLine(
|
||||
color: Colors.grey.withOpacity(0.2),
|
||||
color: Colors.grey.withValues(alpha: 0.2),
|
||||
dashArray: [5, 5],
|
||||
strokeWidth: 1,
|
||||
);
|
||||
@ -192,19 +192,21 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
spots: _chartData
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) => FlSpot(
|
||||
entry.key.toDouble(), entry.value.consumption))
|
||||
.map((entry) => FlSpot(entry.key.toDouble(),
|
||||
entry.value.consumption))
|
||||
.toList(),
|
||||
isCurved: true,
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
color:
|
||||
ColorsManager.primaryColor.withValues(alpha: 0.6),
|
||||
show: true,
|
||||
shadow: const Shadow(color: Colors.black12),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
ColorsManager.primaryColor.withOpacity(0.5),
|
||||
Colors.blue.withOpacity(0.1),
|
||||
ColorsManager.primaryColor
|
||||
.withValues(alpha: 0.5),
|
||||
Colors.blue.withValues(alpha: 0.1),
|
||||
],
|
||||
begin: Alignment.center,
|
||||
end: Alignment.bottomCenter,
|
||||
@ -220,7 +222,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
borderData: FlBorderData(
|
||||
show: false,
|
||||
border: Border.all(
|
||||
color: const Color(0xff023DFE).withOpacity(0.7),
|
||||
color: const Color(0xff023DFE).withValues(alpha: 0.7),
|
||||
width: 10,
|
||||
),
|
||||
),
|
||||
|
||||
@ -9,16 +9,17 @@ import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_
|
||||
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class PowerClampBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class PowerClampBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final List<String> deviceIds;
|
||||
|
||||
const PowerClampBatchControlView({Key? key, required this.deviceIds}) : super(key: key);
|
||||
const PowerClampBatchControlView({super.key, required this.deviceIds});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
SmartPowerBloc(deviceId: deviceIds.first)..add(SmartPowerFetchBatchEvent(deviceIds)),
|
||||
create: (context) => SmartPowerBloc(deviceId: deviceIds.first)
|
||||
..add(SmartPowerFetchBatchEvent(deviceIds)),
|
||||
child: BlocBuilder<SmartPowerBloc, SmartPowerState>(
|
||||
builder: (context, state) {
|
||||
if (state is SmartPowerLoading) {
|
||||
@ -35,7 +36,8 @@ class PowerClampBatchControlView extends StatelessWidget with HelperResponsiveLa
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, PowerClampBatchModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, PowerClampBatchModel status) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
|
||||
@ -9,12 +9,12 @@ class PowerClampInfoCard extends StatelessWidget {
|
||||
final String unit;
|
||||
|
||||
const PowerClampInfoCard({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.iconPath,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.unit,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@ -12,7 +12,8 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
//Smart Power Clamp
|
||||
class SmartPowerDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
class SmartPowerDeviceControl extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final String deviceId;
|
||||
|
||||
const SmartPowerDeviceControl({super.key, required this.deviceId});
|
||||
@ -59,7 +60,7 @@ class SmartPowerDeviceControl extends StatelessWidget with HelperResponsiveLayou
|
||||
required SmartPowerBloc blocProvider,
|
||||
required int currentPage,
|
||||
}) {
|
||||
PageController pageController = PageController(initialPage: currentPage);
|
||||
final pageController = PageController(initialPage: currentPage);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
child: DeviceControlsContainer(
|
||||
@ -195,8 +196,8 @@ class SmartPowerDeviceControl extends StatelessWidget with HelperResponsiveLayou
|
||||
blocProvider.add(SelectDateEvent(context: context));
|
||||
blocProvider.add(FilterRecordsByDateEvent(
|
||||
selectedDate: blocProvider.dateTime!,
|
||||
viewType:
|
||||
blocProvider.views[blocProvider.currentIndex]));
|
||||
viewType: blocProvider
|
||||
.views[blocProvider.currentIndex]));
|
||||
},
|
||||
widget: blocProvider.dateSwitcher(),
|
||||
chartData: blocProvider.energyDataList.isNotEmpty
|
||||
|
||||
@ -4,7 +4,8 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
||||
class DeviceBatchControlDialog extends StatelessWidget
|
||||
with RouteControlsBasedCode {
|
||||
final List<AllDevicesModel> devices;
|
||||
|
||||
const DeviceBatchControlDialog({super.key, required this.devices});
|
||||
@ -43,7 +44,7 @@ class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCo
|
||||
height: 8,
|
||||
),
|
||||
Text(
|
||||
"Batch Control",
|
||||
'Batch Control',
|
||||
style: context.textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
),
|
||||
@ -104,39 +105,39 @@ String getBatchDialogName(AllDevicesModel device) {
|
||||
*/
|
||||
switch (device.productType) {
|
||||
case '1G':
|
||||
return "Smart Light Switch";
|
||||
return 'Smart Light Switch';
|
||||
case '2G':
|
||||
return "Smart Light Switch";
|
||||
return 'Smart Light Switch';
|
||||
case '3G':
|
||||
return "Smart Light Switch";
|
||||
return 'Smart Light Switch';
|
||||
case 'GW':
|
||||
return "Gateway";
|
||||
return 'Gateway';
|
||||
case 'DL':
|
||||
return "Door Lock";
|
||||
return 'Door Lock';
|
||||
case 'WPS':
|
||||
return "White Presence Sensor";
|
||||
return 'White Presence Sensor';
|
||||
case 'CPS':
|
||||
return "Black Presence Sensor";
|
||||
return 'Black Presence Sensor';
|
||||
case 'CUR':
|
||||
return "Smart Curtains";
|
||||
return 'Smart Curtains';
|
||||
case 'WH':
|
||||
return "Smart Water Heater";
|
||||
return 'Smart Water Heater';
|
||||
case 'AC':
|
||||
return "Smart AC";
|
||||
return 'Smart AC';
|
||||
case 'DS':
|
||||
return "Door / Window Sensor";
|
||||
return 'Door / Window Sensor';
|
||||
case '1GT':
|
||||
return "Touch Switch";
|
||||
return 'Touch Switch';
|
||||
case '2GT':
|
||||
return "Touch Switch";
|
||||
return 'Touch Switch';
|
||||
case '3GT':
|
||||
return "Touch Switch";
|
||||
return 'Touch Switch';
|
||||
case 'GD':
|
||||
return "Garage Door Opener";
|
||||
return 'Garage Door Opener';
|
||||
case 'WL':
|
||||
return "Water Leak Sensor";
|
||||
return 'Water Leak Sensor';
|
||||
case 'SOS':
|
||||
return "SOS";
|
||||
return 'SOS';
|
||||
default:
|
||||
return device.categoryName ?? 'Device Control';
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(1),
|
||||
padding: const EdgeInsets.all(1),
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.grey,
|
||||
@ -107,7 +107,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
||||
'Installation Date and Time:',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
((device.createTime ?? 0) * 1000),
|
||||
(device.createTime ?? 0) * 1000,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -115,7 +115,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
||||
'Battery Level:',
|
||||
device.batteryLevel != null
|
||||
? '${device.batteryLevel ?? 0}%'
|
||||
: "-",
|
||||
: '-',
|
||||
statusColor: device.batteryLevel != null
|
||||
? (device.batteryLevel! < 20
|
||||
? ColorsManager.red
|
||||
@ -131,7 +131,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
||||
'Last Offline Date and Time:',
|
||||
formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
((device.updateTime ?? 0) * 1000),
|
||||
(device.updateTime ?? 0) * 1000,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -18,8 +18,9 @@ class DeviceControlsContainer extends StatelessWidget {
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: padding ?? 10, horizontal: padding ?? 16), //EdgeInsets.all(padding ?? 12),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: padding ?? 10,
|
||||
horizontal: padding ?? 16), //EdgeInsets.all(padding ?? 12),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
|
||||
@ -4,7 +4,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class PresenceDisplayValue extends StatelessWidget {
|
||||
const PresenceDisplayValue(
|
||||
{super.key, required this.value, required this.postfix, required this.description});
|
||||
{super.key,
|
||||
required this.value,
|
||||
required this.postfix,
|
||||
required this.description});
|
||||
|
||||
final String value;
|
||||
final String postfix;
|
||||
@ -32,7 +35,9 @@ class PresenceDisplayValue extends StatelessWidget {
|
||||
child: Text(
|
||||
postfix,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontSize: 16, fontWeight: FontWeight.w700),
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -40,7 +45,9 @@ class PresenceDisplayValue extends StatelessWidget {
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class PresenceSpaceType extends StatelessWidget {
|
||||
const PresenceSpaceType({
|
||||
@ -20,7 +20,7 @@ class PresenceSpaceType extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Map<SpaceTypes, String> spaceTypeIcons = {
|
||||
final spaceTypeIcons = <SpaceTypes, String>{
|
||||
SpaceTypes.none: Assets.office,
|
||||
SpaceTypes.parlour: Assets.parlour,
|
||||
SpaceTypes.area: Assets.dyi,
|
||||
|
||||
@ -4,7 +4,8 @@ import 'package:syncrow_web/pages/device_managment/shared/device_controls_contai
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class PresenceStaticWidget extends StatelessWidget {
|
||||
const PresenceStaticWidget({required this.icon, required this.description, super.key});
|
||||
const PresenceStaticWidget(
|
||||
{required this.icon, required this.description, super.key});
|
||||
final String icon;
|
||||
final String description;
|
||||
|
||||
@ -23,7 +24,9 @@ class PresenceStaticWidget extends StatelessWidget {
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -25,7 +25,9 @@ class PresenceState extends StatelessWidget {
|
||||
Text(
|
||||
'Status:',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 10),
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -41,7 +43,9 @@ class PresenceState extends StatelessWidget {
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -48,7 +48,7 @@ class _PresenceUpdateDataState extends State<PresenceNoBodyTime> {
|
||||
|
||||
String _extractNumericValue(String value) {
|
||||
if (value == 'none') return '0';
|
||||
return value.replaceAll(RegExp(r'[a-zA-Z]'), '').trim();
|
||||
return value.replaceAll(RegExp('[a-zA-Z]'), '').trim();
|
||||
}
|
||||
|
||||
String _extractUnit(String value) {
|
||||
@ -69,17 +69,17 @@ class _PresenceUpdateDataState extends State<PresenceNoBodyTime> {
|
||||
}
|
||||
|
||||
void _incrementValue() {
|
||||
int currentIndex = nobodyTimeRange.indexOf(_currentValue);
|
||||
final currentIndex = nobodyTimeRange.indexOf(_currentValue);
|
||||
if (currentIndex < nobodyTimeRange.length - 1) {
|
||||
String newValue = nobodyTimeRange[currentIndex + 1];
|
||||
final newValue = nobodyTimeRange[currentIndex + 1];
|
||||
_onValueChanged(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
void _decrementValue() {
|
||||
int currentIndex = nobodyTimeRange.indexOf(_currentValue);
|
||||
final currentIndex = nobodyTimeRange.indexOf(_currentValue);
|
||||
if (currentIndex > 0) {
|
||||
String newValue = nobodyTimeRange[currentIndex - 1];
|
||||
final newValue = nobodyTimeRange[currentIndex - 1];
|
||||
_onValueChanged(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,8 @@ class ReportsTable extends StatelessWidget {
|
||||
height: 100,
|
||||
child: Text(
|
||||
'No reports found',
|
||||
style: context.textTheme.bodyLarge!.copyWith(color: ColorsManager.grayColor),
|
||||
style: context.textTheme.bodyLarge!
|
||||
.copyWith(color: ColorsManager.grayColor),
|
||||
),
|
||||
)
|
||||
: Stack(
|
||||
@ -49,7 +50,8 @@ class ReportsTable extends StatelessWidget {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Table(
|
||||
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
|
||||
border:
|
||||
TableBorder.all(color: Colors.grey.shade300, width: 1),
|
||||
columnWidths: const {
|
||||
0: FlexColumnWidth(),
|
||||
1: FlexColumnWidth(),
|
||||
@ -66,28 +68,36 @@ class ReportsTable extends StatelessWidget {
|
||||
),
|
||||
if (report.data != null)
|
||||
...report.data!.asMap().entries.map((entry) {
|
||||
int index = entry.key;
|
||||
DeviceEvent data = entry.value;
|
||||
final index = entry.key;
|
||||
final data = entry.value;
|
||||
|
||||
// Parse eventTime into Date and Time
|
||||
DateTime eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
|
||||
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
|
||||
String time = DateFormat('HH:mm').format(eventDateTime);
|
||||
final eventDateTime =
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
data.eventTime!);
|
||||
final date =
|
||||
DateFormat('dd/MM/yyyy').format(eventDateTime);
|
||||
final time = DateFormat('HH:mm').format(eventDateTime);
|
||||
|
||||
String value;
|
||||
if (hideValueShowDescription == true) {
|
||||
if (mainDoorSensor != null && mainDoorSensor == true) {
|
||||
if (mainDoorSensor != null &&
|
||||
mainDoorSensor == true) {
|
||||
value = data.value == 'true' ? 'Open' : 'Close';
|
||||
} else if (garageDoorSensor != null && garageDoorSensor == true) {
|
||||
} else if (garageDoorSensor != null &&
|
||||
garageDoorSensor == true) {
|
||||
value = data.value == 'true' ? 'Opened' : 'Closed';
|
||||
} else if (waterLeak != null && waterLeak == true) {
|
||||
value = data.value == 'normal' ? 'Normal' : 'Leak Detected';
|
||||
value = data.value == 'normal'
|
||||
? 'Normal'
|
||||
: 'Leak Detected';
|
||||
} else {
|
||||
value = '${data.value!} ${thirdColumnDescription ?? ''}';
|
||||
value =
|
||||
'${data.value!} ${thirdColumnDescription ?? ''}';
|
||||
}
|
||||
} else {
|
||||
value = '${data.value!} ${thirdColumnDescription ?? ''}';
|
||||
value =
|
||||
'${data.value!} ${thirdColumnDescription ?? ''}';
|
||||
}
|
||||
|
||||
return TableRow(
|
||||
|
||||
@ -42,29 +42,30 @@ class ToggleWidget extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
icon == '-1'
|
||||
? const SizedBox(
|
||||
height: 60,
|
||||
width: 60,
|
||||
)
|
||||
: ClipOval(
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: 60,
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
icon ?? Assets.lightPulp,
|
||||
width: 35,
|
||||
height: 35,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
)),
|
||||
if (icon == '-1')
|
||||
const SizedBox(
|
||||
height: 60,
|
||||
width: 60,
|
||||
)
|
||||
else
|
||||
ClipOval(
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: 60,
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
icon ?? Assets.lightPulp,
|
||||
width: 35,
|
||||
height: 35,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
)),
|
||||
if (showToggle)
|
||||
Container(
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
activeColor: ColorsManager.dialogBlueTitle,
|
||||
activeTrackColor: ColorsManager.dialogBlueTitle,
|
||||
onChanged: onChange,
|
||||
),
|
||||
),
|
||||
|
||||
@ -22,7 +22,8 @@ class SosDeviceBloc extends Bloc<SosDeviceEvent, SosDeviceState> {
|
||||
|
||||
late SosStatusModel deviceStatus;
|
||||
|
||||
FutureOr<void> _getDeviceStatus(GetDeviceStatus event, Emitter<SosDeviceState> emit) async {
|
||||
FutureOr<void> _getDeviceStatus(
|
||||
GetDeviceStatus event, Emitter<SosDeviceState> emit) async {
|
||||
emit(SosDeviceLoadingState());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.uuid);
|
||||
@ -33,7 +34,8 @@ class SosDeviceBloc extends Bloc<SosDeviceEvent, SosDeviceState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _getBatchStatus(GetBatchStatus event, Emitter<SosDeviceState> emit) async {
|
||||
FutureOr<void> _getBatchStatus(
|
||||
GetBatchStatus event, Emitter<SosDeviceState> emit) async {
|
||||
emit(SosDeviceLoadingState());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.uuids);
|
||||
@ -44,25 +46,31 @@ class SosDeviceBloc extends Bloc<SosDeviceEvent, SosDeviceState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _getDeviceRecords(GetDeviceRecords event, Emitter<SosDeviceState> emit) async {
|
||||
FutureOr<void> _getDeviceRecords(
|
||||
GetDeviceRecords event, Emitter<SosDeviceState> emit) async {
|
||||
emit(SosReportLoadingState());
|
||||
try {
|
||||
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
|
||||
final from = DateTime.now()
|
||||
.subtract(const Duration(days: 30))
|
||||
.millisecondsSinceEpoch;
|
||||
final to = DateTime.now().millisecondsSinceEpoch;
|
||||
final DeviceReport records =
|
||||
await DevicesManagementApi.getDeviceReportsByDate(event.uuid, 'sos', from.toString(), to.toString());
|
||||
final records = await DevicesManagementApi.getDeviceReportsByDate(
|
||||
event.uuid, 'sos', from.toString(), to.toString());
|
||||
emit(SosReportLoadedState(records));
|
||||
} catch (e) {
|
||||
emit(SosReportErrorState(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _getDeviceAutomationRecords(GetDeviceAutomationRecords event, Emitter<SosDeviceState> emit) async {
|
||||
FutureOr<void> _getDeviceAutomationRecords(
|
||||
GetDeviceAutomationRecords event, Emitter<SosDeviceState> emit) async {
|
||||
emit(SosAutomationReportLoadingState());
|
||||
try {
|
||||
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
|
||||
final from = DateTime.now()
|
||||
.subtract(const Duration(days: 30))
|
||||
.millisecondsSinceEpoch;
|
||||
final to = DateTime.now().millisecondsSinceEpoch;
|
||||
final DeviceReport records = await DevicesManagementApi.getDeviceReportsByDate(
|
||||
final records = await DevicesManagementApi.getDeviceReportsByDate(
|
||||
event.uuid, 'sos_automation', from.toString(), to.toString());
|
||||
emit(SosAutomationReportLoadedState(records));
|
||||
} catch (e) {
|
||||
@ -70,14 +78,17 @@ class SosDeviceBloc extends Bloc<SosDeviceEvent, SosDeviceState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _backToSosStatusView(BackToSosStatusView event, Emitter<SosDeviceState> emit) {
|
||||
FutureOr<void> _backToSosStatusView(
|
||||
BackToSosStatusView event, Emitter<SosDeviceState> emit) {
|
||||
emit(SosDeviceLoadedState(deviceStatus));
|
||||
}
|
||||
|
||||
FutureOr<void> _sosFactoryReset(SosFactoryReset event, Emitter<SosDeviceState> emit) async {
|
||||
FutureOr<void> _sosFactoryReset(
|
||||
SosFactoryReset event, Emitter<SosDeviceState> emit) async {
|
||||
emit(SosDeviceLoadingState());
|
||||
try {
|
||||
final response = await DevicesManagementApi().factoryReset(event.factoryReset, event.deviceId);
|
||||
final response = await DevicesManagementApi()
|
||||
.factoryReset(event.factoryReset, event.deviceId);
|
||||
if (response) {
|
||||
emit(SosDeviceLoadedState(deviceStatus));
|
||||
} else {
|
||||
|
||||
@ -15,7 +15,7 @@ class SosStatusModel {
|
||||
late int batteryLevel;
|
||||
late String sosStatus;
|
||||
|
||||
for (var status in statuses) {
|
||||
for (final status in statuses) {
|
||||
switch (status.code) {
|
||||
case 'battery_percentage':
|
||||
batteryLevel = status.value;
|
||||
|
||||
@ -6,13 +6,12 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
||||
import 'package:syncrow_web/pages/device_managment/shared/icon_name_status_container.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/sos/bloc/sos_device_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/sos/models/sos_status_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/sos/widgets/sos_notification_dialog.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
import '../models/sos_status_model.dart';
|
||||
|
||||
class SosDeviceControlsView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const SosDeviceControlsView({
|
||||
@ -56,9 +55,9 @@ class SosDeviceControlsView extends StatelessWidget
|
||||
} else if (state is SosDeviceErrorState) {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
} else if (state is SosAutomationReportErrorState) {
|
||||
return Center(child: Text('Error: ${state.message.toString()}'));
|
||||
return Center(child: Text('Error: ${state.message}'));
|
||||
} else if (state is SosReportErrorState) {
|
||||
return Center(child: Text('Error: ${state.message.toString()}'));
|
||||
return Center(child: Text('Error: ${state.message}'));
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
|
||||
@ -52,7 +52,7 @@ class _NotificationDialogState extends State<SosNotificationDialog> {
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
padding: EdgeInsets.all(1),
|
||||
padding: const EdgeInsets.all(1),
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.grey,
|
||||
|
||||
@ -40,7 +40,8 @@ class ThreeGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(ThreeGangGlassSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(event.deviceId, emit);
|
||||
deviceStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(event.deviceId, status.status);
|
||||
@ -64,7 +65,7 @@ class ThreeGangGlassSwitchBloc
|
||||
|
||||
final statusList = <Status>[];
|
||||
if (data['status'] != null) {
|
||||
for (var element in data['status']) {
|
||||
for (final element in data['status']) {
|
||||
statusList.add(
|
||||
Status(
|
||||
code: element['code'].toString(),
|
||||
@ -74,7 +75,8 @@ class ThreeGangGlassSwitchBloc
|
||||
}
|
||||
}
|
||||
if (statusList.isNotEmpty) {
|
||||
final newStatus = ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
final newStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
|
||||
if (newStatus != deviceStatus) {
|
||||
deviceStatus = newStatus;
|
||||
if (!isClosed) {
|
||||
@ -142,9 +144,10 @@ class ThreeGangGlassSwitchBloc
|
||||
) async {
|
||||
emit(ThreeGangGlassSwitchLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus =
|
||||
ThreeGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.deviceIds);
|
||||
deviceStatus = ThreeGangGlassStatusModel.fromJson(
|
||||
event.deviceIds.first, status.status);
|
||||
emit(ThreeGangGlassSwitchBatchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(ThreeGangGlassSwitchError(e.toString()));
|
||||
|
||||
@ -27,7 +27,7 @@ class ThreeGangGlassStatusModel {
|
||||
late bool switch3;
|
||||
late int countDown3;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false;
|
||||
|
||||
@ -9,16 +9,19 @@ import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/factorie
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/models/three_gang_glass_switch.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final List<String> deviceIds;
|
||||
|
||||
const ThreeGangGlassSwitchBatchControlView({required this.deviceIds, super.key});
|
||||
const ThreeGangGlassSwitchBatchControlView(
|
||||
{required this.deviceIds, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(ThreeGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
create: (context) =>
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(ThreeGangGlassSwitchFetchBatchStatusEvent(deviceIds)),
|
||||
child: BlocBuilder<ThreeGangGlassSwitchBloc, ThreeGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThreeGangGlassSwitchLoading) {
|
||||
@ -35,7 +38,8 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -58,7 +62,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
|
||||
value: status.switch1,
|
||||
code: 'switch_1',
|
||||
deviceId: deviceIds.first,
|
||||
label: "Wall Light",
|
||||
label: 'Wall Light',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
@ -73,7 +77,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
|
||||
value: status.switch2,
|
||||
code: 'switch_2',
|
||||
deviceId: deviceIds.first,
|
||||
label: "Ceiling Light",
|
||||
label: 'Ceiling Light',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
@ -88,7 +92,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
|
||||
value: status.switch3,
|
||||
code: 'switch_3',
|
||||
deviceId: deviceIds.first,
|
||||
label: "SpotLight",
|
||||
label: 'SpotLight',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchBatchControl(
|
||||
|
||||
@ -3,12 +3,12 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/bloc/three_gang_glass_switch_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/factories/three_gang_glass_switch_bloc_factory.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/models/three_gang_glass_switch.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
import '../models/three_gang_glass_switch.dart';
|
||||
|
||||
class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class ThreeGangGlassSwitchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
final String deviceId;
|
||||
|
||||
const ThreeGangGlassSwitchControlView({required this.deviceId, super.key});
|
||||
@ -17,7 +17,8 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceId)..add(ThreeGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
ThreeGangGlassSwitchBlocFactory.create(deviceId: deviceId)
|
||||
..add(ThreeGangGlassSwitchFetchDeviceEvent(deviceId)),
|
||||
child: BlocBuilder<ThreeGangGlassSwitchBloc, ThreeGangGlassSwitchState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThreeGangGlassSwitchLoading) {
|
||||
@ -34,7 +35,8 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, ThreeGangGlassStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -57,7 +59,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
|
||||
value: status.switch1,
|
||||
code: 'switch_1',
|
||||
deviceId: deviceId,
|
||||
label: "Wall Light",
|
||||
label: 'Wall Light',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
@ -72,7 +74,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
|
||||
value: status.switch2,
|
||||
code: 'switch_2',
|
||||
deviceId: deviceId,
|
||||
label: "Ceiling Light",
|
||||
label: 'Ceiling Light',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
@ -87,7 +89,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
|
||||
value: status.switch3,
|
||||
code: 'switch_3',
|
||||
deviceId: deviceId,
|
||||
label: "SpotLight",
|
||||
label: 'SpotLight',
|
||||
onChange: (value) {
|
||||
context.read<ThreeGangGlassSwitchBloc>().add(
|
||||
ThreeGangGlassSwitchControl(
|
||||
|
||||
@ -39,9 +39,11 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
||||
) async {
|
||||
emit(LivingRoomDeviceStatusLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
_listenToChanges(deviceId);
|
||||
deviceStatus = LivingRoomStatusModel.fromJson(event.deviceId, status.status);
|
||||
deviceStatus =
|
||||
LivingRoomStatusModel.fromJson(event.deviceId, status.status);
|
||||
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(LivingRoomDeviceManagementError(e.toString()));
|
||||
@ -52,9 +54,9 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
||||
try {
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
ref.onValue.listen((event) {
|
||||
final eventsMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
final eventsMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
|
||||
List<Status> statusList = [];
|
||||
final statusList = <Status>[];
|
||||
eventsMap['status'].forEach((element) {
|
||||
statusList.add(
|
||||
Status(code: element['code'], value: element['value']),
|
||||
@ -122,7 +124,8 @@ class LivingRoomBloc extends Bloc<LivingRoomEvent, LivingRoomState> {
|
||||
) async {
|
||||
emit(LivingRoomDeviceStatusLoading());
|
||||
try {
|
||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final status =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus =
|
||||
LivingRoomStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
emit(LivingRoomDeviceStatusLoaded(deviceStatus));
|
||||
|
||||
@ -18,7 +18,7 @@ class LivingRoomStatusModel {
|
||||
late bool switch2;
|
||||
late bool switch3;
|
||||
|
||||
for (var status in jsonList) {
|
||||
for (final status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch_1':
|
||||
switch1 = status.value ?? false; // default to false if null
|
||||
|
||||
@ -2,14 +2,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.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/factories/living_room_bloc_factory.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/living_room_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class LivingRoomBatchControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class LivingRoomBatchControlsView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const LivingRoomBatchControlsView({super.key, required this.deviceIds});
|
||||
|
||||
final List<String> deviceIds;
|
||||
@ -18,14 +19,16 @@ class LivingRoomBatchControlsView extends StatelessWidget with HelperResponsiveL
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
LivingRoomBlocFactory.create(deviceId: deviceIds.first)..add(LivingRoomFetchBatchEvent(deviceIds)),
|
||||
LivingRoomBlocFactory.create(deviceId: deviceIds.first)
|
||||
..add(LivingRoomFetchBatchEvent(deviceIds)),
|
||||
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) {
|
||||
} else if (state is LivingRoomDeviceManagementError ||
|
||||
state is LivingRoomControlError) {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@ -35,7 +38,8 @@ class LivingRoomBatchControlsView extends StatelessWidget with HelperResponsiveL
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, LivingRoomStatusModel status) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, LivingRoomStatusModel status) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.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/factories/living_room_bloc_factory.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/models/living_room_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class LivingRoomDeviceControlsView extends StatelessWidget
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/three_gang_switch/bloc/living_room_bloc.dart';
|
||||
@ -7,7 +6,11 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class CeilingLight extends StatelessWidget {
|
||||
const CeilingLight({super.key, required this.value, required this.code, required this.deviceId});
|
||||
const CeilingLight(
|
||||
{super.key,
|
||||
required this.value,
|
||||
required this.code,
|
||||
required this.deviceId});
|
||||
|
||||
final bool value;
|
||||
final String code;
|
||||
@ -23,7 +26,7 @@ class CeilingLight extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ClipOval(
|
||||
child: Container(
|
||||
child: ColoredBox(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: SvgPicture.asset(
|
||||
Assets.lightPulp,
|
||||
@ -37,7 +40,7 @@ class CeilingLight extends StatelessWidget {
|
||||
width: 35,
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
activeColor: ColorsManager.dialogBlueTitle,
|
||||
activeTrackColor: ColorsManager.dialogBlueTitle,
|
||||
onChanged: (newValue) {
|
||||
context.read<LivingRoomBloc>().add(
|
||||
LivingRoomControl(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user