From 8278251754df42db634101b75cebda734dec413e Mon Sep 17 00:00:00 2001 From: Mohit Kumar Singh Date: Sun, 28 Feb 2021 19:15:09 +0530 Subject: [PATCH] fix: Implemented Exception Handling and solved persistent Shimmer in Explorer Screen (#53) --- lib/api/api_requests.dart | 35 +++++++++++++++------------ lib/screens/disk_explorer_screen.dart | 3 ++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/api/api_requests.dart b/lib/api/api_requests.dart index d724cb2..e012dc9 100644 --- a/lib/api/api_requests.dart +++ b/lib/api/api_requests.dart @@ -420,26 +420,31 @@ class ApiRequests { /// Gets Disk Files static Future> getDiskFiles(Api api, String path) async { - var response = await api.ioClient.post(Uri.parse(api.explorerPluginUrl), - headers: api.getAuthHeader(), - body: { - 'cmd': 'get', - 'src': path, - }); + try { + var response = await api.ioClient.post(Uri.parse(api.explorerPluginUrl), + headers: api.getAuthHeader(), + body: { + 'cmd': 'get', + 'src': path, + }); - var files = jsonDecode(response.body)['files']; + var files = jsonDecode(response.body)['files']; - List diskFiles = []; + List diskFiles = []; - for (var file in files) { - DiskFile diskFile = DiskFile(); + for (var file in files) { + DiskFile diskFile = DiskFile(); - diskFile.isDirectory = file['is_dir']; - diskFile.name = file['data']['name']; - diskFiles.add(diskFile); - } + diskFile.isDirectory = file['is_dir']; + diskFile.name = file['data']['name']; + diskFiles.add(diskFile); + } - return diskFiles; + return diskFiles; + } on Exception catch (e) { + print(e.toString()); + return null; + } } static setTorrentLabel(Api api, String hashValue, {String label}) async { diff --git a/lib/screens/disk_explorer_screen.dart b/lib/screens/disk_explorer_screen.dart index bdcfebe..6a5918b 100644 --- a/lib/screens/disk_explorer_screen.dart +++ b/lib/screens/disk_explorer_screen.dart @@ -21,7 +21,8 @@ class _DiskExplorerState extends State { isLoading = true; }); diskFiles = await ApiRequests.getDiskFiles( - Provider.of(context, listen: false), path); + Provider.of(context, listen: false), path) ?? + []; setState(() { isLoading = false; });