diff --git a/lib/utility/local_storage_service.dart b/lib/utility/local_storage_service.dart index ce9c762..ac00835 100644 --- a/lib/utility/local_storage_service.dart +++ b/lib/utility/local_storage_service.dart @@ -68,7 +68,7 @@ class LocalStorageService { } /// Opens the file picker to save a JSON file with the current game data. - static Future exportJsonFile() async { + static Future exportJsonFile() async { final jsonString = getJsonFile(); try { final bytes = Uint8List.fromList(utf8.encode(jsonString)); @@ -79,14 +79,18 @@ class LocalStorageService { mimeType: MimeType.json, ); print('Datei gespeichert: $result'); + return true; } catch (e) { print('Fehler beim Speichern: $e'); + return false; } } + /// Opens the file picker to import a JSON file and loads the game data from it. static Future importJsonFile() async { try { final result = await FilePicker.platform.pickFiles( + dialogTitle: 'Wähle eine Datei mit Spieldaten aus', type: FileType.custom, allowedExtensions: ['json'], ); @@ -108,7 +112,7 @@ class LocalStorageService { return true; } else { print('Der Dialog wurde abgebrochen'); - return false; + return true; } } catch (e) { print('Fehler beim Importieren: $e'); diff --git a/lib/views/information_view.dart b/lib/views/information_view.dart index 04b51a4..6b99e4c 100644 --- a/lib/views/information_view.dart +++ b/lib/views/information_view.dart @@ -83,11 +83,46 @@ class InformationView extends StatelessWidget { ], ), CupertinoButton( + sizeStyle: CupertinoButtonSize.medium, child: const Text('Spieldaten exportieren'), - onPressed: () => LocalStorageService.exportJsonFile()), + onPressed: () async => + await LocalStorageService.exportJsonFile() + ? null + : showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: const Text('Fehler'), + content: const Text( + 'Datei konnte nicht exportiert werden.'), + actions: [ + CupertinoDialogAction( + child: const Text('OK'), + onPressed: () => + Navigator.pop(context), + ), + ], + ))), CupertinoButton( + sizeStyle: CupertinoButtonSize.medium, child: const Text('Spieldaten importieren'), - onPressed: () => LocalStorageService.importJsonFile()), + onPressed: () async => { + await LocalStorageService.importJsonFile() + ? null + : showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( + title: const Text('Fehler'), + content: const Text( + 'Datei konnte nicht importiert werden.'), + actions: [ + CupertinoDialogAction( + child: const Text('OK'), + onPressed: () => + Navigator.pop(context), + ), + ], + )) + }), ], ), Positioned( diff --git a/pubspec.yaml b/pubspec.yaml index 36e7f73..f298aa6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.1.3+107 +version: 0.1.5+108 environment: sdk: ^3.5.4 @@ -11,20 +11,18 @@ dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.8 - font_awesome_flutter: ^10.8.0 - url_launcher: any - package_info_plus: any - flutter_keyboard_visibility: ^6.0.0 - path_provider: ^2.1.1 - file_picker: any + file_picker: ^10.1.2 file_saver: ^0.2.6 + flutter_keyboard_visibility: ^6.0.0 + font_awesome_flutter: ^10.8.0 + package_info_plus: any + path_provider: ^2.1.1 typed_data: ^1.3.2 - + url_launcher: any dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^5.0.0 test: ^1.25.15