mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 08:34:54 +00:00
bugs fixes
This commit is contained in:
@ -161,15 +161,12 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
void _fetchStatus(InitCurtain event, Emitter<CurtainState> emit) async {
|
||||
try {
|
||||
emit(CurtainLoadingState());
|
||||
// Fetch the status from the API
|
||||
var response = await DevicesAPI.getDeviceStatus(curtainId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
// Get the open percentage from the response
|
||||
openPercentage = double.tryParse(statusModelList[1].value.toString())!;
|
||||
// Calculate curtain width and blind height based on the open percentage
|
||||
curtainWidth = 270 - (openPercentage / 100) * curtainOpeningSpace;
|
||||
blindHeight = 310 - (openPercentage / 100) * blindOpeningSpace;
|
||||
|
||||
@ -216,7 +213,6 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
|
||||
if (groupList.isNotEmpty) {
|
||||
groupList.firstWhere((element) {
|
||||
print('object=====${element.percentControl}');
|
||||
if (element.percentControl > 1) {
|
||||
allSwitchesOn = true;
|
||||
}
|
||||
@ -285,7 +281,6 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
|
||||
if (response2['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
// Handle retry or error if needed.
|
||||
}
|
||||
} catch (_) {
|
||||
emit(FailedState());
|
||||
@ -297,7 +292,6 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
void _groupAllOff(GroupAllOffEvent event, Emitter<CurtainState> emit) async {
|
||||
emit(LoadingNewSate(curtainModel: deviceStatus));
|
||||
try {
|
||||
// Set all devices to 'close'
|
||||
for (int i = 0; i < groupList.length; i++) {
|
||||
groupList[i].percentControl = 0;
|
||||
}
|
||||
@ -315,12 +309,10 @@ class CurtainBloc extends Bloc<CurtainEvent, CurtainState> {
|
||||
|
||||
if (response2['failedResults'].toString() != '[]') {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
// Handle retry or error if needed.
|
||||
}
|
||||
} catch (_) {
|
||||
emit(FailedState());
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
// Optionally add an initial event if needed.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,6 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
||||
doorAlarm = event.isDoorAlarmEnabled;
|
||||
emit(UpdateState(doorSensor: deviceStatus));
|
||||
|
||||
// API call to update the state, if necessary
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: DSId,
|
||||
@ -119,33 +118,26 @@ class DoorSensorBloc extends Bloc<DoorSensorEvent, DoorSensorState> {
|
||||
|
||||
Future<void> fetchLogsForLastMonth(
|
||||
ReportLogsInitial event, Emitter<DoorSensorState> emit) async {
|
||||
// Get the current date and time
|
||||
DateTime now = DateTime.now();
|
||||
|
||||
// Calculate the date one month ago
|
||||
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
||||
|
||||
// Convert the date to milliseconds since epoch (Unix timestamp in milliseconds)
|
||||
int startTime = lastMonth.millisecondsSinceEpoch;
|
||||
int endTime = now.millisecondsSinceEpoch;
|
||||
try {
|
||||
emit(DoorSensorLoadingState());
|
||||
var response = await DevicesAPI.getReportLogs(
|
||||
startTime:
|
||||
startTime.toString(), // Convert to String if the API expects it
|
||||
endTime: endTime.toString(), // Convert to String if the API expects it
|
||||
startTime.toString(),
|
||||
endTime: endTime.toString(),
|
||||
deviceUuid: DSId,
|
||||
code: 'doorcontact_state',
|
||||
);
|
||||
print('response======${response}');
|
||||
recordGroups = response;
|
||||
// Process response here
|
||||
emit(UpdateState(doorSensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
// Handle error
|
||||
print('Error fetching logs: ${errorMessage}');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -724,7 +724,8 @@ class ThreeTouchBloc extends Bloc<ThreeTouchEvent, ThreeTouchState> {
|
||||
threeTouchId,
|
||||
);
|
||||
} else {
|
||||
print('Invalid statusSelected or optionSelected');
|
||||
emit(const FailedState(
|
||||
error: 'Invalid statusSelected or optionSelected'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
|
||||
@ -670,7 +670,7 @@ class TwoTouchBloc extends Bloc<TwoTouchEvent, TwoTouchState> {
|
||||
twoTouchId,
|
||||
);
|
||||
} else {
|
||||
print('Invalid statusSelected or optionSelected');
|
||||
emit( const FailedState(error: 'Invalid statusSelected or optionSelected'));
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
|
||||
@ -138,9 +138,10 @@ class GarageDoorScreen extends StatelessWidget {
|
||||
Assets
|
||||
.garageSchedule),
|
||||
),
|
||||
const SizedBox(
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
)),
|
||||
const Flexible(
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
@ -187,9 +188,10 @@ class GarageDoorScreen extends StatelessWidget {
|
||||
Assets
|
||||
.garageCountdown),
|
||||
),
|
||||
const SizedBox(
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
)),
|
||||
const Flexible(
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
@ -238,9 +240,10 @@ class GarageDoorScreen extends StatelessWidget {
|
||||
Assets
|
||||
.doorRecordsIcon),
|
||||
),
|
||||
const SizedBox(
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
)),
|
||||
const Flexible(
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
@ -282,9 +285,10 @@ class GarageDoorScreen extends StatelessWidget {
|
||||
child: SvgPicture.asset(Assets
|
||||
.garagePreferencesIcon),
|
||||
),
|
||||
const SizedBox(
|
||||
const Flexible(
|
||||
child: SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
)),
|
||||
const Flexible(
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
|
||||
@ -97,9 +97,12 @@ class PreferencesPage extends StatelessWidget {
|
||||
Transform.scale(
|
||||
scale: .8,
|
||||
child: CupertinoSwitch(
|
||||
value: garageDoorBloc.deviceStatus.doorState1 != 'unclosed_time',
|
||||
value: garageDoorBloc.deviceStatus
|
||||
.doorState1 !=
|
||||
'unclosed_time',
|
||||
onChanged: (value) {
|
||||
context.read<GarageDoorBloc>()
|
||||
context
|
||||
.read<GarageDoorBloc>()
|
||||
.add(
|
||||
ToggleAlarmEvent(
|
||||
value
|
||||
@ -156,27 +159,27 @@ class PreferencesPage extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const BodyMedium(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 12, bottom: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const BodyMedium(
|
||||
text: 'Opening and Closing Time',
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
trailing: Container(
|
||||
height: 90,
|
||||
width: 120,
|
||||
child: Row(
|
||||
Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
BodyMedium(
|
||||
fontColor: ColorsManager.textGray,
|
||||
text:
|
||||
'${garageDoorBloc.secondSelected.toString()} Seconds',
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 13,
|
||||
),
|
||||
const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
@ -185,7 +188,8 @@ class PreferencesPage extends StatelessWidget {
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@ -177,8 +177,8 @@ class _WaterLeakRecordsScreenState extends State<WaterLeakRecordsScreen> {
|
||||
),
|
||||
title: Text(
|
||||
record.value == 'true'
|
||||
? "Normal"
|
||||
: "Leak Detected",
|
||||
? "Leak Detected"
|
||||
: "Normal",
|
||||
style: const TextStyle(
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
@ -207,6 +207,8 @@ class _WaterLeakRecordsScreenState extends State<WaterLeakRecordsScreen> {
|
||||
Container(
|
||||
height: 10,
|
||||
width: 20,
|
||||
child:
|
||||
const Center(child: Text('No data available.')),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -39,7 +39,6 @@ class DevicesAPI {
|
||||
body: controlModel.toJson(),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
print(json);
|
||||
return json;
|
||||
},
|
||||
);
|
||||
@ -70,7 +69,6 @@ class DevicesAPI {
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
||||
print(deviceId);
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceFunctionsStatus
|
||||
.replaceAll('{deviceUuid}', deviceId),
|
||||
|
||||
Reference in New Issue
Block a user