From 3082148e8c20f7fbaf9aded451714ef5b06466d0 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 29 Sep 2024 12:03:58 +0300 Subject: [PATCH] Bug fixes 2 --- .../bloc/one_gang_bloc/one_gang_bloc.dart | 9 -- .../bloc/three_gang_bloc/three_gang_bloc.dart | 2 +- .../bloc/two_gang_bloc/two_gang_bloc.dart | 113 +++++++++++------ .../water_heater_bloc/water_heater_bloc.dart | 118 +++++++++++++----- 4 files changed, 164 insertions(+), 78 deletions(-) diff --git a/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart b/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart index 1ebe48e..6d40c61 100644 --- a/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart +++ b/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart @@ -296,14 +296,6 @@ class OneGangBloc extends Bloc { } } - // void toggleCreateSchedule() { - // emit(LoadingInitialState()); - // createSchedule = !createSchedule; - // selectedDays.clear(); - // selectedTime = DateTime.now(); - // emit(UpdateCreateScheduleState(createSchedule)); - // emit(ChangeSlidingSegmentState(value: 1)); - // } void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); @@ -358,7 +350,6 @@ class OneGangBloc extends Bloc { for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); } - // deviceStatus = TwoGangModel.fromJson(statusModelList); deviceStatus = OneGangModel.fromJson(statusModelList); groupOneGangList.add(GroupOneGangModel( deviceId: devicesList[i].uuid ?? '', diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart index 2066b10..087d569 100644 --- a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart @@ -114,7 +114,7 @@ class ThreeGangBloc extends Bloc { DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeGangId'); Stream stream = ref.onValue; - stream.listen((DatabaseEvent event) async { + stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart index ce44b9f..6b43274 100644 --- a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart +++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart @@ -35,7 +35,8 @@ class TwoGangBloc extends Bloc { bool createSchedule = false; List listSchedule = []; - TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) { + TwoGangBloc({required this.twoGangId, required this.switchCode}) + : super(InitialState()) { on(_fetchTwoGangStatus); on(_twoGangUpdated); on(_changeFirstSwitch); @@ -65,13 +66,15 @@ class TwoGangBloc extends Bloc { int selectedTabIndex = 0; - void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex( + ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule( + ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); @@ -79,7 +82,8 @@ class TwoGangBloc extends Bloc { emit(UpdateCreateScheduleState(createSchedule)); } - void _fetchTwoGangStatus(InitialEvent event, Emitter emit) async { + void _fetchTwoGangStatus( + InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(twoGangId); @@ -98,18 +102,21 @@ class TwoGangBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId'); + DatabaseReference ref = + FirebaseDatabase.instance.ref('device-status/$twoGangId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = event.snapshot.value as Map; + Map usersMap = + event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList.add(StatusModel(code: element['code'], value: element['value'])); + statusList + .add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = TwoGangModel.fromJson(statusList); @@ -124,7 +131,8 @@ class TwoGangBloc extends Bloc { emit(UpdateState(twoGangModel: deviceStatus)); } - void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch( + ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.firstSwitch = !event.value; @@ -135,7 +143,8 @@ class TwoGangBloc extends Bloc { _timer = Timer(const Duration(milliseconds: 500), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value), + DeviceControlModel( + deviceId: twoGangId, code: 'switch_1', value: !event.value), twoGangId); if (!response['success']) { @@ -147,7 +156,8 @@ class TwoGangBloc extends Bloc { } } - void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter emit) async { + void _changeSecondSwitch( + ChangeSecondSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.secondSwitch = !event.value; @@ -157,7 +167,8 @@ class TwoGangBloc extends Bloc { } _timer = Timer(const Duration(milliseconds: 500), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value), + DeviceControlModel( + deviceId: twoGangId, code: 'switch_2', value: !event.value), twoGangId); if (!response['success']) { @@ -180,11 +191,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), + deviceId: twoGangId, + code: 'switch_1', + value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), + deviceId: twoGangId, + code: 'switch_2', + value: deviceStatus.secondSwitch), twoGangId), ]); @@ -207,11 +222,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), + deviceId: twoGangId, + code: 'switch_1', + value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), + deviceId: twoGangId, + code: 'switch_2', + value: deviceStatus.secondSwitch), twoGangId), ]); if (response.every((element) => !element['success'])) { @@ -232,7 +251,8 @@ class TwoGangBloc extends Bloc { groupTwoGangList[i].secondSwitch = true; } emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true)); - List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupTwoGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -267,18 +287,19 @@ class TwoGangBloc extends Bloc { emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false)); - List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupTwoGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: allDeviceIds, - value: true, + value: false, ); final response2 = await DevicesAPI.deviceBatchController( code: 'switch_2', devicesUuid: allDeviceIds, - value: true, + value: false, ); if (response1['failedResults'].toString() != '[]' || @@ -292,17 +313,20 @@ class TwoGangBloc extends Bloc { } } - void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding( + ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue(SetCounterValue event, Emitter emit) async { + void _setCounterValue( + SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds), + DeviceControlModel( + deviceId: twoGangId, code: event.deviceCode, value: seconds), twoGangId); if (response['success'] ?? false) { @@ -327,7 +351,8 @@ class TwoGangBloc extends Bloc { } } - void _getCounterValue(GetCounterEvent event, Emitter emit) async { + void _getCounterValue( + GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { add(GetScheduleEvent()); @@ -435,7 +460,8 @@ class TwoGangBloc extends Bloc { deviceId: twoGangId, ); List jsonData = response; - listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = + jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -446,12 +472,13 @@ class TwoGangBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = - DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, + dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleRepeat(ToggleScheduleEvent event, Emitter emit) async { + Future toggleRepeat( + ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -470,7 +497,8 @@ class TwoGangBloc extends Bloc { } } - Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule( + DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( @@ -490,7 +518,8 @@ class TwoGangBloc extends Bloc { } } - void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter emit) async { + void _fetchTwoGangWizardStatus( + InitialWizardEvent event, Emitter emit) async { emit(LoadingInitialState()); try { devicesList = []; @@ -500,7 +529,8 @@ class TwoGangBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '2G'); for (int i = 0; i < devicesList.length; i++) { - var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = + await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -523,15 +553,16 @@ class TwoGangBloc extends Bloc { return true; }); } - emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState( + twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); } catch (e) { emit(FailedState(error: e.toString())); return; } } - void _changeFirstWizardSwitch( - ChangeFirstWizardSwitchStatusEvent event, Emitter emit) async { + void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event, + Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -544,9 +575,11 @@ class TwoGangBloc extends Bloc { } }); - emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState( + twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); - List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupTwoGangList.map((device) => device.deviceId).toList(); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: allDeviceIds, @@ -561,8 +594,8 @@ class TwoGangBloc extends Bloc { } } - void _changeSecondWizardSwitch( - ChangeSecondWizardSwitchStatusEvent event, Emitter emit) async { + void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event, + Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -574,9 +607,11 @@ class TwoGangBloc extends Bloc { allSwitchesValue = false; } }); - List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupTwoGangList.map((device) => device.deviceId).toList(); - emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState( + twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_2', diff --git a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart index 97220c6..7d3e29d 100644 --- a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart +++ b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:dio/dio.dart'; +import 'package:firebase_database/firebase_database.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; @@ -34,7 +35,8 @@ class WaterHeaterBloc extends Bloc { List listSchedule = []; DateTime? selectedTime = DateTime.now(); - WaterHeaterBloc({required this.whId, required this.switchCode}) : super(WHInitialState()) { + WaterHeaterBloc({required this.whId, required this.switchCode}) + : super(WHInitialState()) { on(_fetchWaterHeaterStatus); on(_changeFirstSwitch); on(_setCounterValue); @@ -56,9 +58,11 @@ class WaterHeaterBloc extends Bloc { on(_groupAllOn); on(_groupAllOff); on(_toggleCreateCirculate); + on(_waterHeaterUpdated); } - void _fetchWaterHeaterStatus(WaterHeaterInitial event, Emitter emit) async { + void _fetchWaterHeaterStatus( + WaterHeaterInitial event, Emitter emit) async { emit(WHLoadingState()); try { var response = await DevicesAPI.getDeviceStatus(whId); @@ -70,15 +74,48 @@ class WaterHeaterBloc extends Bloc { statusModelList, ); emit(UpdateState(whModel: deviceStatus)); - Future.delayed(const Duration(milliseconds: 500)); - // _listenToChanges(); + _listenToChanges(); } catch (e) { emit(WHFailedState(errorMessage: e.toString())); return; } } - void _changeFirstSwitch(WaterHeaterSwitch event, Emitter emit) async { + _listenToChanges() { + try { + DatabaseReference ref = + FirebaseDatabase.instance.ref('device-status/$whId'); + Stream stream = ref.onValue; + + stream.listen((DatabaseEvent event) async { + if (_timer != null) { + await Future.delayed(const Duration(seconds: 2)); + } + Map usersMap = + event.snapshot.value as Map; + List statusList = []; + + usersMap['status'].forEach((element) { + statusList + .add(StatusModel(code: element['code'], value: element['value'])); + }); + + deviceStatus = WHModel.fromJson(statusList); + if (!isClosed) { + add(WaterHeaterUpdated()); + } + }); + } catch (_) {} + } + + _waterHeaterUpdated( + WaterHeaterUpdated event, Emitter emit) async { + emit(WHLoadingState()); + emit(UpdateState(whModel: deviceStatus)); + } + + void _changeFirstSwitch( + WaterHeaterSwitch event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { deviceStatus.firstSwitch = !event.whSwitch; @@ -88,7 +125,10 @@ class WaterHeaterBloc extends Bloc { } _timer = Timer(const Duration(milliseconds: 500), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: whId, code: 'switch_1', value: deviceStatus.firstSwitch), + DeviceControlModel( + deviceId: whId, + code: 'switch_1', + value: deviceStatus.firstSwitch), whId); if (!response['success']) { @@ -102,13 +142,16 @@ class WaterHeaterBloc extends Bloc { //=====================---------- timer ---------------------------------------- - void _setCounterValue(SetCounterValue event, Emitter emit) async { + void _setCounterValue( + SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: whId, code: event.deviceCode, value: seconds), whId); + DeviceControlModel( + deviceId: whId, code: event.deviceCode, value: seconds), + whId); if (response['success'] ?? false) { if (event.deviceCode == 'countdown_1') { @@ -130,7 +173,8 @@ class WaterHeaterBloc extends Bloc { } } - void _getCounterValue(GetCounterEvent event, Emitter emit) async { + void _getCounterValue( + GetCounterEvent event, Emitter emit) async { emit(WHLoadingState()); try { var response = await DevicesAPI.getDeviceStatus(whId); @@ -220,7 +264,8 @@ class WaterHeaterBloc extends Bloc { deviceId: whId, ); List jsonData = response; - listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = + jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(WHInitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -231,12 +276,13 @@ class WaterHeaterBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = - DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, + dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleChange(ToggleScheduleEvent event, Emitter emit) async { + Future toggleChange( + ToggleScheduleEvent event, Emitter emit) async { try { emit(WHLoadingState()); final response = await DevicesAPI.changeSchedule( @@ -254,7 +300,8 @@ class WaterHeaterBloc extends Bloc { } } - Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule( + DeleteScheduleEvent event, Emitter emit) async { try { emit(WHLoadingState()); final response = await DevicesAPI.deleteSchedule( @@ -273,7 +320,8 @@ class WaterHeaterBloc extends Bloc { } } - void _toggleCreateCirculate(ToggleCreateCirculate event, Emitter emit) { + void _toggleCreateCirculate( + ToggleCreateCirculate event, Emitter emit) { emit(WHLoadingState()); createCirculate = !createCirculate; selectedDays.clear(); @@ -281,13 +329,15 @@ class WaterHeaterBloc extends Bloc { emit(UpdateCreateScheduleState(createCirculate)); } - void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex( + ToggleSelectedEvent event, Emitter emit) { emit(WHLoadingState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule( + ToggleCreateScheduleEvent event, Emitter emit) { emit(WHLoadingState()); createSchedule = !createSchedule; selectedDays.clear(); @@ -336,8 +386,8 @@ class WaterHeaterBloc extends Bloc { List groupWaterHeaterList = []; bool allSwitchesOn = true; - void _changeFirstWizardSwitch( - ChangeFirstWizardSwitchStatusEvent event, Emitter emit) async { + void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event, + Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -349,7 +399,8 @@ class WaterHeaterBloc extends Bloc { allSwitchesValue = false; } }); - emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState( + twoGangList: groupWaterHeaterList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -364,7 +415,8 @@ class WaterHeaterBloc extends Bloc { } } - void _fetchWHWizardStatus(InitialWizardEvent event, Emitter emit) async { + void _fetchWHWizardStatus( + InitialWizardEvent event, Emitter emit) async { emit(WHLoadingState()); try { devicesList = []; @@ -374,7 +426,8 @@ class WaterHeaterBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', 'WH'); for (int i = 0; i < devicesList.length; i++) { - var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = + await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -396,23 +449,27 @@ class WaterHeaterBloc extends Bloc { return true; }); } - emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState( + twoGangList: groupWaterHeaterList, allSwitches: allSwitchesOn)); } catch (e) { // emit(FailedState(error: e.toString())); return; } } - void _groupAllOn(GroupAllOnEvent event, Emitter emit) async { + void _groupAllOn( + GroupAllOnEvent event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { for (int i = 0; i < groupWaterHeaterList.length; i++) { groupWaterHeaterList[i].firstSwitch = true; } - emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: true)); + emit(UpdateGroupState( + twoGangList: groupWaterHeaterList, allSwitches: true)); - List allDeviceIds = groupWaterHeaterList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupWaterHeaterList.map((device) => device.deviceId).toList(); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -430,15 +487,18 @@ class WaterHeaterBloc extends Bloc { } } - void _groupAllOff(GroupAllOffEvent event, Emitter emit) async { + void _groupAllOff( + GroupAllOffEvent event, Emitter emit) async { emit(LoadingNewSate(whModel: deviceStatus)); try { for (int i = 0; i < groupWaterHeaterList.length; i++) { groupWaterHeaterList[i].firstSwitch = false; } - emit(UpdateGroupState(twoGangList: groupWaterHeaterList, allSwitches: false)); + emit(UpdateGroupState( + twoGangList: groupWaterHeaterList, allSwitches: false)); - List allDeviceIds = groupWaterHeaterList.map((device) => device.deviceId).toList(); + List allDeviceIds = + groupWaterHeaterList.map((device) => device.deviceId).toList(); final response = await DevicesAPI.deviceBatchController( code: 'switch_1',