diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-06-09 21:38:29 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2023-06-09 21:38:29 +0200 |
| commit | 629db8d6250bfbab82508e3ab1f083c0e38f605b (patch) | |
| tree | 3645b1c2c64d70cbf44167e2456300ea946a0bc9 /lib/services | |
| parent | 97e0c8cef73064d121dcb38ab904e8d5d8ba5cdd (diff) | |
debug logging
Diffstat (limited to 'lib/services')
| -rw-r--r-- | lib/services/backup_helper_service.dart | 30 | ||||
| -rw-r--r-- | lib/services/storegear_api_service.dart | 5 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/services/backup_helper_service.dart b/lib/services/backup_helper_service.dart new file mode 100644 index 0000000..7a4b7f0 --- /dev/null +++ b/lib/services/backup_helper_service.dart @@ -0,0 +1,30 @@ +import 'dart:io'; + +import 'package:path_provider/path_provider.dart'; + +class BackupHelperService { + Future<String?> getDownloadPath() async { + Directory? directory; + try { + if (Platform.isIOS) { + directory = await getApplicationDocumentsDirectory(); + } else { + directory = Directory('/storage/emulated/0/Download/'); + if (!await directory.exists()) + directory = await getExternalStorageDirectory(); + } + } catch (err, stack) { + print("Cannot get download folder path"); + } + return directory?.path; + } + + Future<void> writeStringToFile(String content, String filename) async { + String? fullpath = await getDownloadPath(); + if (fullpath != null) { + fullpath += filename; + File file = File(fullpath); + file.writeAsString(content); + } + } +} diff --git a/lib/services/storegear_api_service.dart b/lib/services/storegear_api_service.dart index 3063b26..0c2cbbc 100644 --- a/lib/services/storegear_api_service.dart +++ b/lib/services/storegear_api_service.dart @@ -2,10 +2,12 @@ import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; import 'package:training_planner/config/defaults.dart'; +import 'package:training_planner/main.dart'; import 'package:training_planner/models/login_request.dart'; import 'package:training_planner/models/login_response.dart'; import 'package:training_planner/models/route_list.dart'; import 'package:training_planner/route.dart'; +import 'package:training_planner/services/backup_helper_service.dart'; import 'package:training_planner/services/istoregear_api_service.dart'; import 'package:training_planner/route.dart' as DHLRoute; import 'package:training_planner/services/mock_route_provider_service.dart'; @@ -33,6 +35,7 @@ class StoregearApiService extends IStoregearApiService { return res; } else { print(response.body); + backupService.writeStringToFile(response.body, 'failed_login.txt'); // If the server did not return a 200 OK response, // then throw an exception. throw Exception('Failed login'); @@ -65,6 +68,7 @@ class StoregearApiService extends IStoregearApiService { } return RouteList.fromJson(content); } else { + backupService.writeStringToFile(response.body, 'failed_routelist.txt'); // If the server did not return a 200 OK response, // then throw an exception. throw Exception('Failed to load routes'); @@ -92,6 +96,7 @@ class StoregearApiService extends IStoregearApiService { } return RouteInfo.fromJson(content).route; } else { + backupService.writeStringToFile(response.body, 'failed_route.txt'); // If the server did not return a 200 OK response, // then throw an exception. throw Exception('Failed to load route'); |
