Added AlertDialogs for user feedback
This commit is contained in:
@@ -68,7 +68,7 @@ class LocalStorageService {
|
||||
}
|
||||
|
||||
/// Opens the file picker to save a JSON file with the current game data.
|
||||
static Future<void> exportJsonFile() async {
|
||||
static Future<bool> 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<bool> 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');
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user