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.
|
/// 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();
|
final jsonString = getJsonFile();
|
||||||
try {
|
try {
|
||||||
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
||||||
@@ -79,14 +79,18 @@ class LocalStorageService {
|
|||||||
mimeType: MimeType.json,
|
mimeType: MimeType.json,
|
||||||
);
|
);
|
||||||
print('Datei gespeichert: $result');
|
print('Datei gespeichert: $result');
|
||||||
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Fehler beim Speichern: $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 {
|
static Future<bool> importJsonFile() async {
|
||||||
try {
|
try {
|
||||||
final result = await FilePicker.platform.pickFiles(
|
final result = await FilePicker.platform.pickFiles(
|
||||||
|
dialogTitle: 'Wähle eine Datei mit Spieldaten aus',
|
||||||
type: FileType.custom,
|
type: FileType.custom,
|
||||||
allowedExtensions: ['json'],
|
allowedExtensions: ['json'],
|
||||||
);
|
);
|
||||||
@@ -108,7 +112,7 @@ class LocalStorageService {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
print('Der Dialog wurde abgebrochen');
|
print('Der Dialog wurde abgebrochen');
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Fehler beim Importieren: $e');
|
print('Fehler beim Importieren: $e');
|
||||||
|
|||||||
@@ -83,11 +83,46 @@ class InformationView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
CupertinoButton(
|
CupertinoButton(
|
||||||
|
sizeStyle: CupertinoButtonSize.medium,
|
||||||
child: const Text('Spieldaten exportieren'),
|
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(
|
CupertinoButton(
|
||||||
|
sizeStyle: CupertinoButtonSize.medium,
|
||||||
child: const Text('Spieldaten importieren'),
|
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(
|
Positioned(
|
||||||
|
|||||||
16
pubspec.yaml
16
pubspec.yaml
@@ -2,7 +2,7 @@ name: cabo_counter
|
|||||||
description: "Mobile app for the card game Cabo"
|
description: "Mobile app for the card game Cabo"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.1.3+107
|
version: 0.1.5+108
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
@@ -11,20 +11,18 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
font_awesome_flutter: ^10.8.0
|
file_picker: ^10.1.2
|
||||||
url_launcher: any
|
|
||||||
package_info_plus: any
|
|
||||||
flutter_keyboard_visibility: ^6.0.0
|
|
||||||
path_provider: ^2.1.1
|
|
||||||
file_picker: any
|
|
||||||
file_saver: ^0.2.6
|
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
|
typed_data: ^1.3.2
|
||||||
|
url_launcher: any
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
flutter_lints: ^5.0.0
|
flutter_lints: ^5.0.0
|
||||||
test: ^1.25.15
|
test: ^1.25.15
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user