Skip to content

Commit

Permalink
fix: Implemented Exception Handling and solved persistent Shimmer in …
Browse files Browse the repository at this point in the history
…Explorer Screen (#53)
  • Loading branch information
MrUnfunny authored Feb 28, 2021
1 parent 0705bfd commit 8278251
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 20 additions & 15 deletions lib/api/api_requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,26 +420,31 @@ class ApiRequests {

/// Gets Disk Files
static Future<List<DiskFile>> 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<DiskFile> diskFiles = [];
List<DiskFile> 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 {
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/disk_explorer_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class _DiskExplorerState extends State<DiskExplorer> {
isLoading = true;
});
diskFiles = await ApiRequests.getDiskFiles(
Provider.of<Api>(context, listen: false), path);
Provider.of<Api>(context, listen: false), path) ??
[];
setState(() {
isLoading = false;
});
Expand Down

0 comments on commit 8278251

Please sign in to comment.