Revert "formatted all files."

This reverts commit 04250ebc98.
This commit is contained in:
Faris Armoush
2025-06-12 16:04:49 +03:00
parent 218f43bacb
commit c642ba2644
473 changed files with 4335 additions and 5417 deletions

View File

@ -45,8 +45,7 @@ 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;
@ -72,20 +71,21 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
void _listenToChanges(deviceId) {
try {
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
ref.onValue.listen((DatabaseEvent event) async {
final stream = ref.onValue;
stream.listen((DatabaseEvent event) async {
if (event.snapshot.value == null) return;
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
Map<dynamic, dynamic> usersMap =
event.snapshot.value as Map<dynamic, dynamic>;
final statusList = <Status>[];
List<Status> statusList = [];
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,10 +129,8 @@ 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()));
@ -192,8 +190,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
void _handleIncreaseTime(IncreaseTimeEvent event, Emitter<AcsState> emit) {
if (state is! ACStatusLoaded) return;
final currentState = state as ACStatusLoaded;
var newHours = scheduledHours;
var newMinutes = scheduledMinutes + 30;
int newHours = scheduledHours;
int newMinutes = scheduledMinutes + 30;
newHours += newMinutes ~/ 60;
newMinutes = newMinutes % 60;
if (newHours > 23) {
@ -215,7 +213,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
) {
if (state is! ACStatusLoaded) return;
final currentState = state as ACStatusLoaded;
var totalMinutes = (scheduledHours * 60) + scheduledMinutes;
int totalMinutes = (scheduledHours * 60) + scheduledMinutes;
totalMinutes = (totalMinutes - 30).clamp(0, 1440);
scheduledHours = totalMinutes ~/ 60;
scheduledMinutes = totalMinutes % 60;
@ -288,7 +286,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
void _startCountdownTimer(Emitter<AcsState> emit) {
_countdownTimer?.cancel();
var totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
int totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (totalSeconds > 0) {
@ -338,26 +336,32 @@ 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;
}

View File

@ -22,7 +22,7 @@ class AcFetchDeviceStatusEvent extends AcsEvent {
class AcStatusUpdated extends AcsEvent {
final AcStatusModel deviceStatus;
const AcStatusUpdated(this.deviceStatus);
AcStatusUpdated(this.deviceStatus);
}
class AcFetchBatchStatusEvent extends AcsEvent {
@ -77,6 +77,8 @@ class AcFactoryResetEvent extends AcsEvent {
List<Object> get props => [deviceId, factoryResetModel];
}
class OnClose extends AcsEvent {}
class IncreaseTimeEvent extends AcsEvent {
@ -93,7 +95,8 @@ class ToggleScheduleEvent extends AcsEvent {}
class TimerCompletedEvent extends AcsEvent {}
class UpdateTimerEvent extends AcsEvent {}
class UpdateTimerEvent extends AcsEvent {
}
class ApiCountdownValueEvent extends AcsEvent {
final int apiValue;

View File

@ -18,7 +18,6 @@ class ACStatusLoaded extends AcsState {
final DateTime timestamp;
final int scheduledHours;
final int scheduledMinutes;
@override
final bool isTimerActive;
ACStatusLoaded({
@ -73,3 +72,5 @@ class TimerRunInProgress extends AcsState {
@override
List<Object> get props => [remainingTime];
}

View File

@ -32,9 +32,9 @@ class AcStatusModel {
late int currentTemp;
late String fanSpeeds;
late bool childLock;
late var countdown1 = 0;
late int _countdown1 = 0;
for (final status in jsonList) {
for (var 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,
);
}

View File

@ -15,8 +15,7 @@ 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;
@ -101,8 +100,8 @@ class AcDeviceBatchControlView extends StatelessWidget
),
Text(
'h',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blackColor),
style:
context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor),
),
Text(
'30',
@ -149,8 +148,7 @@ class AcDeviceBatchControlView extends StatelessWidget
callFactoryReset: () {
context.read<AcBloc>().add(AcFactoryResetEvent(
deviceId: state.status.uuid,
factoryResetModel:
FactoryResetModel(devicesUuid: devicesIds),
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
));
},
),

View File

@ -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;

View File

@ -41,7 +41,7 @@ class _CurrentTempState extends State<BatchCurrentTemp> {
double _initialAdjustedValue(dynamic value) {
if (value is int || value is double) {
final double doubleValue = value.toDouble();
double doubleValue = value.toDouble();
return doubleValue > 99 ? doubleValue / 10 : doubleValue;
} else {
throw ArgumentError('Invalid value type: Expected int or double');
@ -75,48 +75,35 @@ class _CurrentTempState extends State<BatchCurrentTemp> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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(
widget.isBatch == true
? Text(
'Set Temperature',
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
)
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(widget.currentTemp > 99
? widget.currentTemp / 10
: widget.currentTemp)
.toString(),
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.grey),
'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,
)
],
),
const CelsiusSymbol(
color: Colors.grey,
)
],
),
],
),
const Spacer(),
IncrementDecrementWidget(
value: _adjustedValue.toString(),

View File

@ -52,7 +52,7 @@ class AcToggle extends StatelessWidget {
height: 20,
width: 35,
child: CupertinoSwitch(
activeTrackColor: ColorsManager.dialogBlueTitle,
activeColor: ColorsManager.dialogBlueTitle,
value: value,
onChanged: (newValue) {
context.read<AcBloc>().add(

View File

@ -39,7 +39,7 @@ class _CurrentTempState extends State<CurrentTemp> {
double _initialAdjustedValue(dynamic value) {
if (value is int || value is double) {
final double doubleValue = value.toDouble();
double doubleValue = value.toDouble();
return doubleValue > 99 ? doubleValue / 10 : doubleValue;
} else {
throw ArgumentError('Invalid value type: Expected int or double');
@ -60,7 +60,6 @@ class _CurrentTempState extends State<CurrentTemp> {
);
});
}
@override
void didUpdateWidget(CurrentTemp oldWidget) {
super.didUpdateWidget(oldWidget);
@ -70,7 +69,6 @@ class _CurrentTempState extends State<CurrentTemp> {
});
}
}
@override
void dispose() {
_debounce?.cancel();
@ -89,10 +87,7 @@ 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,
@ -100,14 +95,8 @@ 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,

View File

@ -16,7 +16,7 @@ class DeviceManagementBloc
int _onlineCount = 0;
int _offlineCount = 0;
int _lowBatteryCount = 0;
final List<AllDevicesModel> _selectedDevices = [];
List<AllDevicesModel> _selectedDevices = [];
List<AllDevicesModel> _filteredDevices = [];
String currentProductName = '';
String? currentCommunity;
@ -37,21 +37,20 @@ class DeviceManagementBloc
FetchDevices event, Emitter<DeviceManagementState> emit) async {
emit(DeviceManagementLoading());
try {
var devices = <AllDevicesModel>[];
List<AllDevicesModel> devices = [];
_devices.clear();
final spaceBloc = event.context.read<SpaceTreeBloc>();
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var 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 (final community in spaceBloc.state.selectedCommunities) {
final spacesList =
for (var community in spaceBloc.state.selectedCommunities) {
List<String> spacesList =
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
for (final space in spacesList) {
devices.addAll(await DevicesManagementApi()
.fetchDevices(community, space, projectUuid));
for (var space in spacesList) {
devices.addAll(await DevicesManagementApi().fetchDevices(
community, space, projectUuid));
}
}
}
@ -74,7 +73,7 @@ class DeviceManagementBloc
}
}
Future<void> _onFilterDevices(
void _onFilterDevices(
FilterDevices event, Emitter<DeviceManagementState> emit) async {
if (_devices.isNotEmpty) {
_filteredDevices = List.from(_devices.where((device) {
@ -166,9 +165,9 @@ class DeviceManagementBloc
_selectedDevices.add(event.selectedDevice);
}
final clonedSelectedDevices = List<AllDevicesModel>.from(_selectedDevices);
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
final isControlButtonEnabled =
bool isControlButtonEnabled =
_checkIfControlButtonEnabled(clonedSelectedDevices);
if (state is DeviceManagementLoaded) {
@ -198,8 +197,8 @@ class DeviceManagementBloc
void _onUpdateSelection(
UpdateSelection event, Emitter<DeviceManagementState> emit) {
final selectedDevices = <AllDevicesModel>[];
var devicesToSelectFrom = <AllDevicesModel>[];
List<AllDevicesModel> selectedDevices = [];
List<AllDevicesModel> devicesToSelectFrom = [];
if (state is DeviceManagementLoaded) {
devicesToSelectFrom = (state as DeviceManagementLoaded).devices;
@ -207,7 +206,7 @@ class DeviceManagementBloc
devicesToSelectFrom = (state as DeviceManagementFiltered).filteredDevices;
}
for (var i = 0; i < event.selectedRows.length; i++) {
for (int i = 0; i < event.selectedRows.length; i++) {
if (event.selectedRows[i]) {
selectedDevices.add(devicesToSelectFrom[i]);
}
@ -295,7 +294,7 @@ class DeviceManagementBloc
currentCommunity = event.community;
currentUnitName = event.unitName;
final devicesToSearch = _filteredDevices;
List<AllDevicesModel> devicesToSearch = _filteredDevices;
if (devicesToSearch.isNotEmpty) {
final filteredDevices = devicesToSearch.where((device) {

View File

@ -18,7 +18,6 @@ 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';
@ -40,6 +39,8 @@ 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) {
@ -106,7 +107,7 @@ mixin RouteControlsBasedCode {
case 'SOS':
return SosDeviceControlsView(device: device);
case 'NCPS':
case 'NCPS':
return FlushMountedPresenceSensorControlView(device: device);
default:
return const SizedBox();
@ -131,133 +132,76 @@ 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();

View File

@ -5,12 +5,7 @@ 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() ?? '';

View File

@ -212,8 +212,8 @@ PC
SOS
*/
final type = devicesTypesMap[productType] ?? DeviceType.Other;
var tempIcon = '';
DeviceType type = devicesTypesMap[productType] ?? DeviceType.Other;
String tempIcon = '';
if (type == DeviceType.LightBulb) {
tempIcon = Assets.lightBulb;
} else if (type == DeviceType.CeilingSensor ||
@ -441,9 +441,13 @@ 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:
@ -561,23 +565,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,
};
}

View File

@ -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,3 +58,4 @@ class FactoryResetModel {
@override
int get hashCode => devicesUuid.hashCode;
}

View File

@ -24,13 +24,13 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
Widget build(BuildContext context) {
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
builder: (context, state) {
var devicesToShow = <AllDevicesModel>[];
var selectedIndex = 0;
var onlineCount = 0;
var offlineCount = 0;
var lowBatteryCount = 0;
var isControlButtonEnabled = false;
var selectedDevices = <AllDevicesModel>[];
List<AllDevicesModel> devicesToShow = [];
int selectedIndex = 0;
int onlineCount = 0;
int offlineCount = 0;
int lowBatteryCount = 0;
bool isControlButtonEnabled = false;
List<AllDevicesModel> selectedDevices = [];
if (state is DeviceManagementLoaded) {
devicesToShow = state.devices;
@ -194,23 +194,18 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
device.name ?? '',
device.productName ?? '',
device.uuid ?? '',
if (device.spaces != null &&
device.spaces!.isNotEmpty)
device.spaces![0].spaceName
else
'',
(device.spaces != null &&
device.spaces!.isNotEmpty)
? device.spaces![0].spaceName
: '',
combinedSpaceNames,
if (device.batteryLevel != null)
'${device.batteryLevel}%'
else
'-',
device.batteryLevel != null
? '${device.batteryLevel}%'
: '-',
formatDateTime(
DateTime.fromMillisecondsSinceEpoch(
(device.createTime ?? 0) * 1000)),
if (device.online == true)
'Online'
else
'Offline',
device.online == true ? 'Online' : 'Offline',
formatDateTime(
DateTime.fromMillisecondsSinceEpoch(
(device.updateTime ?? 0) * 1000)),
@ -248,7 +243,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(

View File

@ -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(),
],
);

View File

@ -37,8 +37,7 @@ 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);
@ -55,12 +54,11 @@ 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);
@ -180,8 +178,7 @@ 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) {

View File

@ -85,6 +85,8 @@ class CeilingFactoryResetEvent extends CeilingSensorEvent {
List<Object> get props => [devicesId, factoryResetModel];
}
class StatusUpdated extends CeilingSensorEvent {
final CeilingSensorModel deviceStatus;
const StatusUpdated(this.deviceStatus);

View File

@ -26,53 +26,48 @@ class CeilingSensorModel {
});
factory CeilingSensorModel.fromJson(List<Status> jsonList) {
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;
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;
try {
for (final status in jsonList) {
for (var 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;
}
}
@ -81,15 +76,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,
);
}

View File

@ -12,8 +12,7 @@ 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;
@ -29,12 +28,11 @@ class CeilingSensorBatchControlView extends StatelessWidget
)..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'));
},
@ -42,8 +40,8 @@ class CeilingSensorBatchControlView extends StatelessWidget
);
}
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,
@ -118,8 +116,7 @@ class CeilingSensorBatchControlView extends StatelessWidget
context.read<CeilingSensorBloc>().add(
CeilingFactoryResetEvent(
devicesId: devicesIds.first,
factoryResetModel:
FactoryResetModel(devicesUuid: devicesIds),
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
),
);
},

View File

@ -34,8 +34,7 @@ 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));
@ -55,7 +54,7 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
final statusList = <Status>[];
if (data['status'] != null) {
for (final element in data['status']) {
for (var element in data['status']) {
statusList.add(
Status(
code: element['code'].toString(),
@ -122,8 +121,7 @@ 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) {

View File

@ -60,8 +60,7 @@ class CurtainFactoryReset extends CurtainEvent {
@override
List<Object> get props => [deviceId, factoryReset];
}
class StatusUpdated extends CurtainEvent {
final bool deviceStatus;
const StatusUpdated(this.deviceStatus);
}
}

View File

@ -1,6 +1,7 @@
import 'package:equatable/equatable.dart';
sealed class CurtainState extends Equatable {
sealed class CurtainState extends Equatable {
const CurtainState();
@override

View File

@ -12,8 +12,8 @@ class CurtainModel {
});
factory CurtainModel.fromJson(dynamic json) {
final statusList = json['status'] as List;
final status = statusList.map((i) => Status.fromJson(i)).toList();
var statusList = json['status'] as List;
List<Status> status = statusList.map((i) => Status.fromJson(i)).toList();
return CurtainModel(
productUuid: json['productUuid'],

View File

@ -10,8 +10,7 @@ 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;
@ -19,8 +18,8 @@ class CurtainBatchStatusView extends StatelessWidget
@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) {

View File

@ -2,13 +2,12 @@ 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/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/bloc/setting_bloc_state.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> {
@ -38,7 +37,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';
}
@ -67,8 +66,8 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
DeviceSettingInitialInfo event, Emitter<DeviceSettingsState> emit) async {
try {
emit(DeviceSettingsLoading());
final response = await DevicesManagementApi.getDeviceInfo(deviceId);
final deviceInfo = DeviceInfoModel.fromJson(response);
var response = await DevicesManagementApi.getDeviceInfo(deviceId);
DeviceInfoModel deviceInfo = DeviceInfoModel.fromJson(response);
nameController.text = deviceInfo.name;
emit(DeviceSettingsUpdate(
deviceName: nameController.text,
@ -93,7 +92,9 @@ 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();
@ -105,7 +106,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
));
}
Future<void> _deleteDevice(
void _deleteDevice(
SettingBlocDeleteDevice event, Emitter<DeviceSettingsState> emit) async {
try {
emit(DeviceSettingsLoading());
@ -122,7 +123,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
}
}
Future<void> _onAssignDevice(
void _onAssignDevice(
SettingBlocAssignRoom event, Emitter<DeviceSettingsState> emit) async {
try {
emit(DeviceSettingsLoading());
@ -142,7 +143,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
}
}
Future<void> _fetchRooms(
void _fetchRooms(
SettingBlocFetchRooms event, Emitter<DeviceSettingsState> emit) async {
try {
emit(DeviceSettingsLoading());

View File

@ -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
.withValues(alpha: 0.7),
.withOpacity(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
.withValues(alpha: 0.5),
backgroundColor:
ColorsManager.grayBorder.withOpacity(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: const InputDecoration(
decoration: 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: ColoredBox(
color: Colors.black.withValues(alpha: 0.1),
child: Container(
color: Colors.black.withOpacity(0.1),
child: const Center(
child: CircularProgressIndicator(
color: ColorsManager.primaryColor,

View File

@ -20,9 +20,9 @@ class SubSpaceModel {
}
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
final devices = <DeviceModel>[];
List<DeviceModel> devices = [];
if (json['devices'] != null) {
for (final device in json['devices']) {
for (var device in json['devices']) {
devices.add(DeviceModel.fromJson(device));
}
}

View File

@ -12,11 +12,11 @@ class SubSpaceDialog extends StatefulWidget {
final void Function(SubSpaceModel?) onConfirmed;
const SubSpaceDialog({
super.key,
Key? 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: const Color(0xFF2962FF),
activeColor: 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),

View File

@ -22,15 +22,17 @@ class DoorLockBloc extends Bloc<DoorLockEvent, DoorLockState> {
on<StatusUpdated>(_onStatusUpdated);
}
void _listenToChanges(deviceId) {
_listenToChanges(deviceId) {
try {
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
final stream = ref.onValue;
DatabaseReference ref =
FirebaseDatabase.instance.ref('device-status/$deviceId');
Stream<DatabaseEvent> stream = ref.onValue;
stream.listen((DatabaseEvent event) {
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
Map<dynamic, dynamic> usersMap =
event.snapshot.value as Map<dynamic, dynamic>;
final statusList = <Status>[];
List<Status> statusList = [];
usersMap['status'].forEach((element) {
statusList
.add(Status(code: element['code'], value: element['value']));

View File

@ -1,3 +1,4 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_status_model.dart';

View File

@ -60,7 +60,7 @@ class DoorLockStatusModel {
late String remoteNoDpKey;
late bool normalOpenSwitch;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'unlock_fingerprint':
unlockFingerprint = status.value ?? 0;

View File

@ -7,8 +7,7 @@ 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;

View File

@ -90,7 +90,7 @@ class _DoorLockButtonState extends State<DoorLockButton>
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.grey.withValues(alpha: 0.5),
color: Colors.grey.withOpacity(0.5),
blurRadius: 18,
blurStyle: BlurStyle.outer,
),

View File

@ -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 extends Bloc<
);
}
Future<void> _onFlushMountedPresenceSensorFetchStatusEvent(
void _onFlushMountedPresenceSensorFetchStatusEvent(
FlushMountedPresenceSensorFetchStatusEvent event,
Emitter<FlushMountedPresenceSensorState> emit,
) async {
@ -76,8 +76,7 @@ class FlushMountedPresenceSensorBloc extends Bloc<
) 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) {
@ -92,9 +91,9 @@ class FlushMountedPresenceSensorBloc extends Bloc<
);
ref.onValue.listen((event) {
final eventsMap = event.snapshot.value! as Map<dynamic, dynamic>;
final eventsMap = event.snapshot.value as Map<dynamic, dynamic>;
final statusList = <Status>[];
List<Status> statusList = [];
eventsMap['status'].forEach((element) {
statusList.add(
Status(code: element['code'], value: element['value']),
@ -114,7 +113,7 @@ class FlushMountedPresenceSensorBloc extends Bloc<
}
}
Future<void> _onFlushMountedPresenceSensorChangeValueEvent(
void _onFlushMountedPresenceSensorChangeValueEvent(
FlushMountedPresenceSensorChangeValueEvent event,
Emitter<FlushMountedPresenceSensorState> emit,
) async {
@ -197,8 +196,7 @@ class FlushMountedPresenceSensorBloc extends Bloc<
deviceReport: value, code: event.code));
});
} catch (e) {
emit(FlushMountedPresenceSensorDeviceReportsFailedState(
error: e.toString()));
emit(FlushMountedPresenceSensorDeviceReportsFailedState(error: e.toString()));
return;
}
}

View File

@ -59,8 +59,7 @@ class FlushMountedPresenceSensorGetDeviceReportsEvent
class FlushMountedPresenceSensorShowDescriptionEvent
extends FlushMountedPresenceSensorEvent {
final String description;
const FlushMountedPresenceSensorShowDescriptionEvent(
{required this.description});
const FlushMountedPresenceSensorShowDescriptionEvent({required this.description});
}
class FlushMountedPresenceSensorBackToGridViewEvent

View File

@ -13,8 +13,7 @@ class FlushMountedPresenceSensorInitialState
class FlushMountedPresenceSensorLoadingInitialState
extends FlushMountedPresenceSensorState {}
class FlushMountedPresenceSensorUpdateState
extends FlushMountedPresenceSensorState {
class FlushMountedPresenceSensorUpdateState extends FlushMountedPresenceSensorState {
final FlushMountedPresenceSensorModel model;
const FlushMountedPresenceSensorUpdateState({required this.model});
@ -31,8 +30,7 @@ class FlushMountedPresenceSensorLoadingNewSate
List<Object> get props => [model];
}
class FlushMountedPresenceSensorFailedState
extends FlushMountedPresenceSensorState {
class FlushMountedPresenceSensorFailedState extends FlushMountedPresenceSensorState {
final String error;
const FlushMountedPresenceSensorFailedState({required this.error});
@ -60,8 +58,7 @@ class FlushMountedPresenceSensorDeviceReportsState
class FlushMountedPresenceSensorDeviceReportsFailedState
extends FlushMountedPresenceSensorState {
const FlushMountedPresenceSensorDeviceReportsFailedState(
{required this.error});
const FlushMountedPresenceSensorDeviceReportsFailedState({required this.error});
final String error;
@ -71,8 +68,7 @@ class FlushMountedPresenceSensorDeviceReportsFailedState
class FlushMountedPresenceSensorShowDescriptionState
extends FlushMountedPresenceSensorState {
const FlushMountedPresenceSensorShowDescriptionState(
{required this.description});
const FlushMountedPresenceSensorShowDescriptionState({required this.description});
final String description;
@override

View File

@ -9,10 +9,8 @@ abstract final class FlushMountedPresenceSensorBlocFactory {
}) {
return FlushMountedPresenceSensorBloc(
deviceId: deviceId,
controlDeviceService:
DeviceBlocDependenciesFactory.createControlDeviceService(),
batchControlDevicesService:
DeviceBlocDependenciesFactory.createBatchControlDevicesService(),
controlDeviceService: DeviceBlocDependenciesFactory.createControlDeviceService(),
batchControlDevicesService: DeviceBlocDependenciesFactory.createBatchControlDevicesService(),
);
}
}

View File

@ -37,18 +37,18 @@ class FlushMountedPresenceSensorModel {
int sensiReduce;
factory FlushMountedPresenceSensorModel.fromJson(List<Status> jsonList) {
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;
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;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case codePresenceState:
presenceState = status.value ?? 'presence';
@ -97,3 +97,7 @@ class FlushMountedPresenceSensorModel {
);
}
}

View File

@ -66,14 +66,13 @@ 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),
@ -115,14 +114,13 @@ 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(),
@ -130,17 +128,16 @@ 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,
value: (model.presenceDelay / 10).toDouble(),
title: 'Target Confirm Time:',
description: 's',
minValue: 0.0,
@ -157,7 +154,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
),
),
PresenceUpdateData(
value: model.noneDelay / 10,
value: ((model.noneDelay / 10).toDouble()),
description: 's',
title: 'Disappe Delay:',
minValue: 20,

View File

@ -15,8 +15,7 @@ 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;
@ -38,9 +37,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
@ -57,8 +56,7 @@ 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);
@ -107,13 +105,12 @@ 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),
@ -153,13 +150,12 @@ 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(),
@ -167,16 +163,15 @@ 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,
value: (model.presenceDelay / 10).toDouble(),
valuesPercision: 1,
title: 'Target Confirm Time:',
description: 's',
@ -192,7 +187,7 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
),
),
PresenceUpdateData(
value: model.noneDelay / 10,
value: (model.noneDelay / 10).toDouble(),
description: 's',
title: 'Disappe Delay:',
minValue: 20,

View File

@ -2,6 +2,7 @@ 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';
@ -41,15 +42,17 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
on<EditGarageDoorScheduleEvent>(_onEditSchedule);
on<StatusUpdated>(_onStatusUpdated);
}
void _listenToChanges(deviceId) {
_listenToChanges(deviceId) {
try {
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
final stream = ref.onValue;
DatabaseReference ref =
FirebaseDatabase.instance.ref('device-status/$deviceId');
Stream<DatabaseEvent> stream = ref.onValue;
stream.listen((DatabaseEvent event) {
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
Map<dynamic, dynamic> usersMap =
event.snapshot.value as Map<dynamic, dynamic>;
final statusList = <Status>[];
List<Status> statusList = [];
usersMap['status'].forEach((element) {
statusList
.add(Status(code: element['code'], value: element['value']));
@ -69,11 +72,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
emit(GarageDoorLoadedState(status: deviceStatus));
}
Future<void> _fetchGarageDoorStatus(
void _fetchGarageDoorStatus(
GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
emit(GarageDoorLoadingState());
try {
final response =
var response =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = GarageDoorStatusModel.fromJson(deviceId, response.status);
_listenToChanges(deviceId);
@ -100,13 +103,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
Future<void> _addSchedule(
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
final newSchedule = ScheduleEntry(
ScheduleEntry newSchedule = ScheduleEntry(
category: event.category,
time: formatTimeOfDayToISO(event.time),
function: Status(code: 'doorcontact_state', value: event.functionOn),
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
);
final success =
bool success =
await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
if (success) {
add(FetchGarageDoorSchedulesEvent(
@ -153,7 +156,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
return schedule;
}).toList();
final success = await DevicesManagementApi().updateScheduleRecord(
bool success = await DevicesManagementApi().updateScheduleRecord(
enable: event.enable,
uuid: deviceStatus.uuid,
scheduleId: event.scheduleId,
@ -172,7 +175,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event,
Emitter<GarageDoorState> emit) async {
try {
final success = await DevicesManagementApi()
bool success = await DevicesManagementApi()
.deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
if (success) {
final updatedSchedules = deviceStatus.schedules
@ -192,7 +195,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
Emitter<GarageDoorState> emit) async {
emit(ScheduleGarageLoadingState());
try {
final schedules = await DevicesManagementApi()
List<ScheduleModel> schedules = await DevicesManagementApi()
.getDeviceSchedules(deviceStatus.uuid, event.category);
deviceStatus = deviceStatus.copyWith(schedules: schedules);
emit(
@ -223,7 +226,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
final updatedDays = List<bool>.from(currentState.selectedDays);
List<bool> updatedDays = List.from(currentState.selectedDays);
updatedDays[event.dayIndex] = event.isSelected;
emit(currentState.copyWith(
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
@ -261,8 +264,9 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
.subtract(const Duration(days: 30))
.millisecondsSinceEpoch;
final to = DateTime.now().millisecondsSinceEpoch;
final records = await DevicesManagementApi.getDeviceReportsByDate(
event.deviceId, 'switch_1', from.toString(), to.toString());
final DeviceReport records =
await DevicesManagementApi.getDeviceReportsByDate(
event.deviceId, 'switch_1', from.toString(), to.toString());
emit(GarageDoorReportsState(deviceReport: records));
} catch (e) {
emit(GarageDoorReportsFailedState(error: e.toString()));
@ -348,12 +352,12 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _increaseDelay(
void _increaseDelay(
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
// if (deviceStatus.countdown1 != 0) {
try {
deviceStatus = deviceStatus.copyWith(
delay: deviceStatus.delay + const Duration(minutes: 10));
delay: deviceStatus.delay + Duration(minutes: 10));
emit(GarageDoorLoadedState(status: deviceStatus));
add(GarageDoorControlEvent(
deviceId: deviceId,
@ -365,13 +369,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
// }
}
Future<void> _decreaseDelay(
void _decreaseDelay(
DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
// if (deviceStatus.countdown1 != 0) {
try {
if (deviceStatus.delay.inMinutes > 10) {
deviceStatus = deviceStatus.copyWith(
delay: deviceStatus.delay - const Duration(minutes: 10));
delay: deviceStatus.delay - Duration(minutes: 10));
}
emit(GarageDoorLoadedState(status: deviceStatus));
add(GarageDoorControlEvent(
@ -384,7 +388,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
//}
}
Future<void> _garageDoorControlEvent(
void _garageDoorControlEvent(
GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
final oldValue = event.code == 'countdown_1'
? deviceStatus.countdown1
@ -485,14 +489,14 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
FutureOr<void> _onEditSchedule(
EditGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
final newSchedule = ScheduleEntry(
ScheduleEntry 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),
);
final success = await DevicesManagementApi()
bool success = await DevicesManagementApi()
.editScheduleRecord(deviceId, newSchedule);
if (success) {
add(FetchGarageDoorSchedulesEvent(

View File

@ -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,10 +77,9 @@ class GarageDoorDialogHelper {
backgroundColor: ColorsManager.boxColor,
borderRadius: 15,
onPressed: () async {
final time = await showTimePicker(
TimeOfDay? 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(
@ -100,9 +99,7 @@ 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,
),
@ -117,8 +114,7 @@ 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),
],
@ -192,9 +188,9 @@ class GarageDoorDialogHelper {
static List<bool> _convertDaysStringToBooleans(List<String> selectedDays) {
final daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
final daysBoolean = List<bool>.filled(7, false);
List<bool> daysBoolean = List.filled(7, false);
for (var i = 0; i < daysOfWeek.length; i++) {
for (int i = 0; i < daysOfWeek.length; i++) {
if (selectedDays.contains(daysOfWeek[i])) {
daysBoolean[i] = true;
}
@ -203,9 +199,7 @@ 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(
@ -215,9 +209,7 @@ 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]),
@ -227,23 +219,19 @@ 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'),
@ -252,9 +240,7 @@ 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'),
@ -311,17 +297,13 @@ 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);
@ -329,11 +311,8 @@ 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',
@ -342,10 +321,9 @@ 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",
),
);
}),
@ -370,17 +348,13 @@ 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);

View File

@ -39,9 +39,9 @@ class GarageDoorStatusModel {
late String doorControl1;
late bool voiceControl1;
late String doorState1;
final schedules = <ScheduleModel>[]; // Initialize schedules
List<ScheduleModel> schedules = []; // Initialize schedules
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'switch_1':
switch1 = status.value ?? false;

View File

@ -11,11 +11,10 @@ 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({super.key, required this.deviceIds});
const GarageDoorBatchControlView({Key? key, required this.deviceIds}) : super(key: key);
@override
Widget build(BuildContext context) {
@ -38,8 +37,7 @@ class GarageDoorBatchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, GarageDoorStatusModel status) {
Widget _buildStatusControls(BuildContext context, GarageDoorStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);

View File

@ -1,3 +1,4 @@
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';
@ -7,8 +8,7 @@ class OpeningAndClosingTimeDialogBody extends StatefulWidget {
final ValueChanged<int> onDurationChanged;
final GarageDoorBloc bloc;
const OpeningAndClosingTimeDialogBody({
super.key,
OpeningAndClosingTimeDialogBody({
required this.onDurationChanged,
required this.bloc,
});

View File

@ -26,8 +26,7 @@ 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(
@ -51,21 +50,17 @@ 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));
}
@ -83,8 +78,7 @@ 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(
@ -118,8 +112,7 @@ 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),
],
),
),
@ -141,8 +134,7 @@ 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(
@ -160,8 +152,7 @@ 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,
@ -169,9 +160,7 @@ 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(
@ -181,24 +170,18 @@ 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,
@ -206,8 +189,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
},
child: Text(
'Delete',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blueColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blueColor),
),
),
],
@ -219,8 +201,8 @@ class ScheduleGarageTableWidget extends StatelessWidget {
String _getSelectedDays(List<bool> selectedDays) {
final days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
final selectedDaysStr = <String>[];
for (var i = 0; i < selectedDays.length; i++) {
List<String> selectedDaysStr = [];
for (int i = 0; i < selectedDays.length; i++) {
if (selectedDays[i]) {
selectedDaysStr.add(days[i]);
}

View File

@ -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),

View File

@ -35,8 +35,7 @@ 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,

View File

@ -4,8 +4,7 @@ class SecondsPicker extends StatefulWidget {
final int initialSeconds;
final ValueChanged<int> onSecondsChanged;
const SecondsPicker({
super.key,
SecondsPicker({
required this.initialSeconds,
required this.onSecondsChanged,
});

View File

@ -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 {
const TimeOutAlarmDialogBody(this.bloc, {super.key});
TimeOutAlarmDialogBody(this.bloc);
final GarageDoorBloc bloc;
@override

View File

@ -16,12 +16,10 @@ 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 {
final devicesList =
await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
List<DeviceModel> devicesList = await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
emit(UpdateGatewayState(list: devicesList));
} catch (e) {
@ -30,8 +28,7 @@ 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(

View File

@ -6,8 +6,7 @@ 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;
@ -39,8 +38,7 @@ class GatewayBatchControlView extends StatelessWidget
context.read<GateWayBloc>().add(
GateWayFactoryReset(
deviceId: gatewayIds.first,
factoryReset:
FactoryResetModel(devicesUuid: gatewayIds),
factoryReset: FactoryResetModel(devicesUuid: gatewayIds),
),
);
},

View File

@ -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,
),

View File

@ -159,15 +159,17 @@ class MainDoorSensorBloc
}
}
void _listenToChanges(deviceId) {
_listenToChanges(deviceId) {
try {
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
final stream = ref.onValue;
DatabaseReference ref =
FirebaseDatabase.instance.ref('device-status/$deviceId');
Stream<DatabaseEvent> stream = ref.onValue;
stream.listen((DatabaseEvent event) {
final usersMap = event.snapshot.value! as Map<dynamic, dynamic>;
Map<dynamic, dynamic> usersMap =
event.snapshot.value as Map<dynamic, dynamic>;
final statusList = <Status>[];
List<Status> statusList = [];
usersMap['status'].forEach((element) {
statusList
.add(Status(code: element['code'], value: element['value']));

View File

@ -1,7 +1,8 @@
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 => [];
@ -74,7 +75,7 @@ class MainDoorSensorFactoryReset extends MainDoorSensorEvent {
class StatusUpdated extends MainDoorSensorEvent {
final MainDoorSensorStatusModel deviceStatus;
StatusUpdated(this.deviceStatus);
StatusUpdated(this.deviceStatus);
@override
List<Object> get props => [deviceStatus];
}

View File

@ -12,10 +12,10 @@ class MainDoorSensorStatusModel {
});
factory MainDoorSensorStatusModel.fromJson(String id, List<Status> jsonList) {
late var doorContactState = false;
late var batteryPercentage = 0;
late bool doorContactState = false;
late int batteryPercentage = 0;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'doorcontact_state':
doorContactState = status.value ?? false;

View File

@ -12,8 +12,7 @@ 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;
@ -21,12 +20,10 @@ class MainDoorSensorControlView extends StatelessWidget
@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);
@ -35,15 +32,12 @@ class MainDoorSensorControlView extends StatelessWidget
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());
@ -52,8 +46,7 @@ class MainDoorSensorControlView extends StatelessWidget
));
}
Widget _buildStatusControls(
BuildContext context, MainDoorSensorStatusModel status) {
Widget _buildStatusControls(BuildContext context, MainDoorSensorStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
@ -78,9 +71,7 @@ class MainDoorSensorControlView extends StatelessWidget
icon: Assets.openCloseDoor,
onTap: () {},
status: status.doorContactState,
textColor: status.doorContactState
? ColorsManager.red
: ColorsManager.blackColor,
textColor: status.doorContactState ? ColorsManager.red : ColorsManager.blackColor,
paddingAmount: 8,
),
IconNameStatusContainer(
@ -88,9 +79,7 @@ class MainDoorSensorControlView extends StatelessWidget
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(

View File

@ -27,8 +27,7 @@ class MainDoorSensorBatchView extends StatelessWidget {
BlocProvider.of<MainDoorSensorBloc>(innerContext).add(
MainDoorSensorFactoryReset(
deviceId: devicesIds.first,
factoryReset:
FactoryResetModel(devicesUuid: devicesIds),
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
),
);
},

View File

@ -53,7 +53,7 @@ class _NotificationDialogState extends State<NotificationDialog> {
),
),
child: IconButton(
padding: const EdgeInsets.all(1),
padding: EdgeInsets.all(1),
icon: const Icon(
Icons.close,
color: Colors.grey,

View File

@ -39,11 +39,9 @@ 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()));
@ -64,7 +62,7 @@ class OneGangGlassSwitchBloc
final statusList = <Status>[];
if (data['status'] != null) {
for (final element in data['status']) {
for (var element in data['status']) {
statusList.add(
Status(
code: element['code'].toString(),
@ -74,8 +72,7 @@ class OneGangGlassSwitchBloc
}
}
if (statusList.isNotEmpty) {
final newStatus =
OneGangGlassStatusModel.fromJson(deviceId, statusList);
final newStatus = OneGangGlassStatusModel.fromJson(deviceId, statusList);
if (newStatus != deviceStatus) {
deviceStatus = newStatus;
if (!isClosed) {
@ -143,10 +140,9 @@ 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()));

View File

@ -15,7 +15,7 @@ class OneGangGlassStatusModel {
late bool switch1;
late int countDown;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'switch_1':
switch1 = status.value ?? false;
@ -46,6 +46,5 @@ class OneGangGlassStatusModel {
}
@override
String toString() =>
'OneGangGlassStatusModel(uuid: $uuid, switch1: $switch1, countDown: $countDown)';
String toString() => 'OneGangGlassStatusModel(uuid: $uuid, switch1: $switch1, countDown: $countDown)';
}

View File

@ -8,19 +8,16 @@ 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) {
@ -37,8 +34,7 @@ class OneGangGlassSwitchBatchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, OneGangGlassStatusModel status) {
Widget _buildStatusControls(BuildContext context, OneGangGlassStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);

View File

@ -7,8 +7,7 @@ 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});
@ -17,8 +16,7 @@ class OneGangGlassSwitchControlView extends StatelessWidget
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) {
@ -35,8 +33,7 @@ class OneGangGlassSwitchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, OneGangGlassStatusModel status) {
Widget _buildStatusControls(BuildContext context, OneGangGlassStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
@ -59,7 +56,7 @@ class OneGangGlassSwitchControlView extends StatelessWidget
value: status.switch1,
code: 'switch_1',
deviceId: deviceId,
label: 'Wall Light',
label: "Wall Light",
onChange: (value) {
context.read<OneGangGlassSwitchBloc>().add(
OneGangGlassSwitchControl(

View File

@ -10,8 +10,7 @@ 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;
@ -36,11 +35,9 @@ class WallLightSwitchBloc
) 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()));
@ -61,7 +58,7 @@ class WallLightSwitchBloc
final statusList = <Status>[];
if (data['status'] != null) {
for (final element in data['status']) {
for (var element in data['status']) {
statusList.add(
Status(
code: element['code'].toString(),
@ -139,8 +136,7 @@ class WallLightSwitchBloc
) 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));

View File

@ -15,7 +15,7 @@ class WallLightStatusModel {
late bool switch1;
late int countDown;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'switch_1':
switch1 = status.value ?? false;

View File

@ -10,8 +10,7 @@ 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;
@ -19,17 +18,15 @@ class WallLightBatchControlView extends StatelessWidget
@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());
@ -39,8 +36,7 @@ class WallLightBatchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, WallLightStatusModel status) {
Widget _buildStatusControls(BuildContext context, WallLightStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
@ -82,8 +78,7 @@ class WallLightBatchControlView extends StatelessWidget
FactoryResetWidget(
callFactoryReset: () {
context.read<WallLightSwitchBloc>().add(WallLightFactoryReset(
deviceId: status.uuid,
factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
deviceId: status.uuid, factoryReset: FactoryResetModel(devicesUuid: deviceIds)));
},
),
],

View File

@ -215,46 +215,33 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
SmartPowerFetchDeviceEvent event, Emitter<SmartPowerState> emit) async {
emit(SmartPowerLoading());
try {
final status =
var 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());
@ -318,7 +305,8 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
try {
final response =
await DevicesManagementApi().getPowerStatus(event.devicesIds);
final deviceStatus = PowerClampBatchModel.fromJson(response);
PowerClampBatchModel deviceStatus =
PowerClampBatchModel.fromJson(response);
emit(SmartPowerLoadBatchControll(deviceStatus));
} catch (e) {
@ -429,15 +417,15 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
}
Future<DateTime?> selectMonthAndYear(BuildContext context) async {
var selectedYear = DateTime.now().year;
var selectedMonth = DateTime.now().month;
int selectedYear = DateTime.now().year;
int selectedMonth = DateTime.now().month;
final yearController =
FixedExtentScrollController yearController =
FixedExtentScrollController(initialItem: selectedYear - 1905);
final monthController =
FixedExtentScrollController monthController =
FixedExtentScrollController(initialItem: selectedMonth - 1);
return showDialog<DateTime>(
return await showDialog<DateTime>(
context: context,
builder: (BuildContext context) {
return Column(
@ -549,11 +537,11 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
}
Future<DateTime?> selectYear(BuildContext context) async {
var selectedYear = DateTime.now().year;
final yearController =
int selectedYear = DateTime.now().year;
FixedExtentScrollController yearController =
FixedExtentScrollController(initialItem: selectedYear - 1905);
return showDialog<DateTime>(
return await showDialog<DateTime>(
context: context,
builder: (BuildContext context) {
return Column(
@ -634,9 +622,9 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
Future<DateTime?> dayMonthYearPicker({
required BuildContext context,
}) async {
var selectedDate = DateTime.now();
DateTime selectedDate = DateTime.now();
return showDialog<DateTime>(
return await showDialog<DateTime>(
context: context,
builder: (BuildContext context) {
return Column(
@ -698,7 +686,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now());
Future<void> checkDayMonthYearSelected(
void checkDayMonthYearSelected(
SelectDateEvent event, Emitter<SmartPowerState> emit) async {
Future<DateTime?> Function(BuildContext context)? dateSelector;
String dateFormat;
@ -710,11 +698,15 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
dateFormat = 'yyyy/MM/dd';
break;
case 1:
dateSelector = selectMonthAndYear;
dateSelector = (context) {
return selectMonthAndYear(context);
};
dateFormat = 'yyyy-MM';
break;
case 2:
dateSelector = selectYear;
dateSelector = (context) {
return selectYear(context);
};
dateFormat = 'yyyy';
break;
default:
@ -751,7 +743,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
.toList();
} else if (event.viewType == 'Month') {
formattedDate =
'${event.selectedDate.year}-${getMonthShortName(event.selectedDate.month)}';
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}";
filteredRecords = record
.where((record) =>
@ -760,7 +752,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
.toList();
} else if (event.viewType == 'Day') {
formattedDate =
'${event.selectedDate.year}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}';
"${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}";
filteredRecords = record
.where((record) =>
@ -792,11 +784,11 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
String endChartDate = '';
Future<void> selectDateRange() async {
final startDate = dateTime!;
final endDate = DateTime(startDate.year, startDate.month + 1, 1)
void selectDateRange() async {
DateTime startDate = dateTime!;
DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1)
.subtract(const Duration(days: 1));
final formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
endChartDate = ' - $formattedEndDate';
}
}

View File

@ -95,18 +95,16 @@ 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,
@ -114,4 +112,4 @@ class PowerBatchControlEvent extends SmartPowerEvent {
@override
List<Object> get props => [deviceIds, code, value];
}
}

View File

@ -1,3 +1,4 @@
class EventDevice {
final String? code;
final DateTime? eventTime;
@ -11,7 +12,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() => {

View File

@ -19,10 +19,10 @@ class PowerClampBatchModel extends PowerClampModel1 {
});
factory PowerClampBatchModel.fromJson(Map<String, dynamic> json) {
final String productUuid = json['productUuid'] ?? '';
final String productType = json['productType'] ?? '';
String productUuid = json['productUuid'] ?? '';
String productType = json['productType'] ?? '';
var statusList = <Status>[];
List<Status> statusList = [];
if (json['status'] != null && json['status'] is List) {
statusList =
(json['status'] as List).map((e) => Status.fromJson(e)).toList();

View File

@ -16,8 +16,7 @@ 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>? ?? {}),
);
}

View File

@ -5,8 +5,7 @@ import 'package:syncrow_web/utils/constants/assets.dart';
class PhaseWidget extends StatefulWidget {
final List<Map<String, dynamic>> phaseData;
const PhaseWidget({
super.key,
PhaseWidget({
required this.phaseData,
});
@override
@ -20,7 +19,7 @@ class _PhaseWidgetState extends State<PhaseWidget> {
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(height: 10),
SizedBox(height: 10),
Row(
children: List.generate(widget.phaseData.length, (index) {
return InkWell(
@ -44,28 +43,27 @@ class _PhaseWidgetState extends State<PhaseWidget> {
);
}),
),
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',
),
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',
),
],
);
}

View File

@ -35,7 +35,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
@override
Widget build(BuildContext context) {
return ColoredBox(
return Container(
color: ColorsManager.whiteColors,
child: Column(
children: [
@ -146,7 +146,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
showTitles: false,
reservedSize: 70,
getTitlesWidget: (value, meta) {
final index = value.toInt();
int 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.withValues(alpha: 0.2),
color: Colors.grey.withOpacity(0.2),
dashArray: [8, 8],
strokeWidth: 1,
);
},
getDrawingHorizontalLine: (value) {
return FlLine(
color: Colors.grey.withValues(alpha: 0.2),
color: Colors.grey.withOpacity(0.2),
dashArray: [5, 5],
strokeWidth: 1,
);
@ -192,21 +192,19 @@ 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.withValues(alpha: 0.6),
color: ColorsManager.primaryColor.withOpacity(0.6),
show: true,
shadow: const Shadow(color: Colors.black12),
belowBarData: BarAreaData(
show: true,
gradient: LinearGradient(
colors: [
ColorsManager.primaryColor
.withValues(alpha: 0.5),
Colors.blue.withValues(alpha: 0.1),
ColorsManager.primaryColor.withOpacity(0.5),
Colors.blue.withOpacity(0.1),
],
begin: Alignment.center,
end: Alignment.bottomCenter,
@ -222,7 +220,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
borderData: FlBorderData(
show: false,
border: Border.all(
color: const Color(0xff023DFE).withValues(alpha: 0.7),
color: const Color(0xff023DFE).withOpacity(0.7),
width: 10,
),
),

View File

@ -9,17 +9,16 @@ 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({super.key, required this.deviceIds});
const PowerClampBatchControlView({Key? key, required this.deviceIds}) : super(key: key);
@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) {
@ -36,8 +35,7 @@ class PowerClampBatchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, PowerClampBatchModel status) {
Widget _buildStatusControls(BuildContext context, PowerClampBatchModel status) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [

View File

@ -9,12 +9,12 @@ class PowerClampInfoCard extends StatelessWidget {
final String unit;
const PowerClampInfoCard({
super.key,
Key? key,
required this.iconPath,
required this.title,
required this.value,
required this.unit,
});
}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@ -12,8 +12,7 @@ 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});
@ -60,7 +59,7 @@ class SmartPowerDeviceControl extends StatelessWidget
required SmartPowerBloc blocProvider,
required int currentPage,
}) {
final pageController = PageController(initialPage: currentPage);
PageController pageController = PageController(initialPage: currentPage);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: DeviceControlsContainer(
@ -196,8 +195,8 @@ class SmartPowerDeviceControl extends StatelessWidget
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

View File

@ -4,8 +4,7 @@ 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});
@ -44,7 +43,7 @@ class DeviceBatchControlDialog extends StatelessWidget
height: 8,
),
Text(
'Batch Control',
"Batch Control",
style: context.textTheme.bodySmall!.copyWith(
color: ColorsManager.dialogBlueTitle,
),
@ -105,39 +104,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';
}

View File

@ -50,7 +50,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
),
),
child: IconButton(
padding: const EdgeInsets.all(1),
padding: 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),
),
),
),

View File

@ -18,9 +18,8 @@ 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,
),
);

View File

@ -4,10 +4,7 @@ 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;
@ -35,9 +32,7 @@ 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),
),
),
],
@ -45,9 +40,7 @@ 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),
),
],
),

View File

@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.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/utils/constants/assets.dart';
import 'package:syncrow_web/utils/extension/build_context_x.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';
class PresenceSpaceType extends StatelessWidget {
const PresenceSpaceType({
@ -20,7 +20,7 @@ class PresenceSpaceType extends StatelessWidget {
@override
Widget build(BuildContext context) {
final spaceTypeIcons = <SpaceTypes, String>{
final Map<SpaceTypes, String> spaceTypeIcons = {
SpaceTypes.none: Assets.office,
SpaceTypes.parlour: Assets.parlour,
SpaceTypes.area: Assets.dyi,

View File

@ -4,8 +4,7 @@ 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;
@ -24,9 +23,7 @@ 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),
),
],
),

View File

@ -25,9 +25,7 @@ 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),
),
],
),
@ -43,9 +41,7 @@ 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),
),
],
),

View File

@ -48,7 +48,7 @@ class _PresenceUpdateDataState extends State<PresenceNoBodyTime> {
String _extractNumericValue(String value) {
if (value == 'none') return '0';
return value.replaceAll(RegExp('[a-zA-Z]'), '').trim();
return value.replaceAll(RegExp(r'[a-zA-Z]'), '').trim();
}
String _extractUnit(String value) {
@ -69,17 +69,17 @@ class _PresenceUpdateDataState extends State<PresenceNoBodyTime> {
}
void _incrementValue() {
final currentIndex = nobodyTimeRange.indexOf(_currentValue);
int currentIndex = nobodyTimeRange.indexOf(_currentValue);
if (currentIndex < nobodyTimeRange.length - 1) {
final newValue = nobodyTimeRange[currentIndex + 1];
String newValue = nobodyTimeRange[currentIndex + 1];
_onValueChanged(newValue);
}
}
void _decrementValue() {
final currentIndex = nobodyTimeRange.indexOf(_currentValue);
int currentIndex = nobodyTimeRange.indexOf(_currentValue);
if (currentIndex > 0) {
final newValue = nobodyTimeRange[currentIndex - 1];
String newValue = nobodyTimeRange[currentIndex - 1];
_onValueChanged(newValue);
}
}

View File

@ -41,8 +41,7 @@ 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(
@ -50,8 +49,7 @@ 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(),
@ -68,36 +66,28 @@ class ReportsTable extends StatelessWidget {
),
if (report.data != null)
...report.data!.asMap().entries.map((entry) {
final index = entry.key;
final data = entry.value;
int index = entry.key;
DeviceEvent data = entry.value;
// Parse eventTime into Date and Time
final eventDateTime =
DateTime.fromMillisecondsSinceEpoch(
data.eventTime!);
final date =
DateFormat('dd/MM/yyyy').format(eventDateTime);
final time = DateFormat('HH:mm').format(eventDateTime);
DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
String 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(

View File

@ -42,30 +42,29 @@ class ToggleWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
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,
),
)),
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 (showToggle)
Container(
child: CupertinoSwitch(
value: value,
activeTrackColor: ColorsManager.dialogBlueTitle,
activeColor: ColorsManager.dialogBlueTitle,
onChanged: onChange,
),
),

View File

@ -22,8 +22,7 @@ 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);
@ -34,8 +33,7 @@ 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);
@ -46,31 +44,25 @@ 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 records = await DevicesManagementApi.getDeviceReportsByDate(
event.uuid, 'sos', from.toString(), to.toString());
final DeviceReport 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 records = await DevicesManagementApi.getDeviceReportsByDate(
final DeviceReport records = await DevicesManagementApi.getDeviceReportsByDate(
event.uuid, 'sos_automation', from.toString(), to.toString());
emit(SosAutomationReportLoadedState(records));
} catch (e) {
@ -78,17 +70,14 @@ 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 {

View File

@ -15,7 +15,7 @@ class SosStatusModel {
late int batteryLevel;
late String sosStatus;
for (final status in statuses) {
for (var status in statuses) {
switch (status.code) {
case 'battery_percentage':
batteryLevel = status.value;

View File

@ -6,12 +6,13 @@ 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({
@ -55,9 +56,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}'));
return Center(child: Text('Error: ${state.message.toString()}'));
} else if (state is SosReportErrorState) {
return Center(child: Text('Error: ${state.message}'));
return Center(child: Text('Error: ${state.message.toString()}'));
}
return const Center(child: CircularProgressIndicator());
},

View File

@ -52,7 +52,7 @@ class _NotificationDialogState extends State<SosNotificationDialog> {
),
),
child: IconButton(
padding: const EdgeInsets.all(1),
padding: EdgeInsets.all(1),
icon: const Icon(
Icons.close,
color: Colors.grey,

View File

@ -40,8 +40,7 @@ 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);
@ -65,7 +64,7 @@ class ThreeGangGlassSwitchBloc
final statusList = <Status>[];
if (data['status'] != null) {
for (final element in data['status']) {
for (var element in data['status']) {
statusList.add(
Status(
code: element['code'].toString(),
@ -75,8 +74,7 @@ class ThreeGangGlassSwitchBloc
}
}
if (statusList.isNotEmpty) {
final newStatus =
ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
final newStatus = ThreeGangGlassStatusModel.fromJson(deviceId, statusList);
if (newStatus != deviceStatus) {
deviceStatus = newStatus;
if (!isClosed) {
@ -144,10 +142,9 @@ 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()));

View File

@ -27,7 +27,7 @@ class ThreeGangGlassStatusModel {
late bool switch3;
late int countDown3;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'switch_1':
switch1 = status.value ?? false;

View File

@ -9,19 +9,16 @@ 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) {
@ -38,8 +35,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, ThreeGangGlassStatusModel status) {
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
@ -62,7 +58,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
value: status.switch1,
code: 'switch_1',
deviceId: deviceIds.first,
label: 'Wall Light',
label: "Wall Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(
@ -77,7 +73,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
value: status.switch2,
code: 'switch_2',
deviceId: deviceIds.first,
label: 'Ceiling Light',
label: "Ceiling Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(
@ -92,7 +88,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget
value: status.switch3,
code: 'switch_3',
deviceId: deviceIds.first,
label: 'SpotLight',
label: "SpotLight",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(

View File

@ -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';
class ThreeGangGlassSwitchControlView extends StatelessWidget
with HelperResponsiveLayout {
import '../models/three_gang_glass_switch.dart';
class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperResponsiveLayout {
final String deviceId;
const ThreeGangGlassSwitchControlView({required this.deviceId, super.key});
@ -17,8 +17,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
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) {
@ -35,8 +34,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, ThreeGangGlassStatusModel status) {
Widget _buildStatusControls(BuildContext context, ThreeGangGlassStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
@ -59,7 +57,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
value: status.switch1,
code: 'switch_1',
deviceId: deviceId,
label: 'Wall Light',
label: "Wall Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(
@ -74,7 +72,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
value: status.switch2,
code: 'switch_2',
deviceId: deviceId,
label: 'Ceiling Light',
label: "Ceiling Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(
@ -89,7 +87,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget
value: status.switch3,
code: 'switch_3',
deviceId: deviceId,
label: 'SpotLight',
label: "SpotLight",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(

View File

@ -39,11 +39,9 @@ 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()));
@ -54,9 +52,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>;
final statusList = <Status>[];
List<Status> statusList = [];
eventsMap['status'].forEach((element) {
statusList.add(
Status(code: element['code'], value: element['value']),
@ -124,8 +122,7 @@ 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));

View File

@ -18,7 +18,7 @@ class LivingRoomStatusModel {
late bool switch2;
late bool switch3;
for (final status in jsonList) {
for (var status in jsonList) {
switch (status.code) {
case 'switch_1':
switch1 = status.value ?? false; // default to false if null

View File

@ -2,15 +2,14 @@ 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;
@ -19,16 +18,14 @@ class LivingRoomBatchControlsView extends StatelessWidget
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());
@ -38,8 +35,7 @@ class LivingRoomBatchControlsView extends StatelessWidget
);
}
Widget _buildStatusControls(
BuildContext context, LivingRoomStatusModel status) {
Widget _buildStatusControls(BuildContext context, LivingRoomStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);

View File

@ -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

View File

@ -1,4 +1,5 @@
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';
@ -6,11 +7,7 @@ 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;
@ -26,7 +23,7 @@ class CeilingLight extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipOval(
child: ColoredBox(
child: Container(
color: ColorsManager.whiteColors,
child: SvgPicture.asset(
Assets.lightPulp,
@ -40,7 +37,7 @@ class CeilingLight extends StatelessWidget {
width: 35,
child: CupertinoSwitch(
value: value,
activeTrackColor: ColorsManager.dialogBlueTitle,
activeColor: 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