From a65c602725e051aaf4eee2235dfe348382ec8386 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Sun, 4 Aug 2024 18:15:01 +0300 Subject: [PATCH] push low connection --- .../scene_devices/scene_devices_body.dart | 2 +- lib/services/api/home_management_api.dart | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart index 60e97c8..b5296b7 100644 --- a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart +++ b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart @@ -118,7 +118,7 @@ class SceneDevicesBody extends StatelessWidget { }, ); } else if (state.error != null) { - return Center(child: Text(state.error!)); + return const Center(child: Text('Something went wrong')); } else { return const SizedBox(); } diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index b49e8d7..52777d9 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -13,22 +13,26 @@ class HomeManagementAPI { var userId = await storage.read(key: UserModel.userUuidKey) ?? ''; List list = []; - await _httpService.get( - path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), - showServerMessage: false, - expectedResponseModel: (json) { - json.forEach((value) { - list.add(DeviceModel.fromJson(value)); + try { + await _httpService.get( + path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId), + showServerMessage: false, + expectedResponseModel: (json) { + json.forEach((value) { + list.add(DeviceModel.fromJson(value)); + }); }); - }); + } catch (e) { + rethrow; + } return list; } static Future> fetchDevicesByUnitId() async { List list = []; await _httpService.get( - path: ApiEndpoints.getDevicesByUnitId - .replaceAll("{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''), + path: ApiEndpoints.getDevicesByUnitId.replaceAll( + "{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''), showServerMessage: false, expectedResponseModel: (json) { json.forEach((value) { @@ -38,7 +42,8 @@ class HomeManagementAPI { return list; } - static Future> assignDeviceToRoom(Map body) async { + static Future> assignDeviceToRoom( + Map body) async { try { final response = await _httpService.put( path: ApiEndpoints.assignDeviceToRoom,