Implementing single game export
This commit is contained in:
@@ -103,12 +103,12 @@ class LocalStorageService {
|
||||
}
|
||||
|
||||
/// Opens the file picker to save a JSON file with the current game data.
|
||||
static Future<bool> exportJsonFile() async {
|
||||
static Future<bool> exportGameData() async {
|
||||
final jsonString = getJsonFile();
|
||||
try {
|
||||
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
||||
final result = await FileSaver.instance.saveAs(
|
||||
name: 'cabo_counter_data',
|
||||
name: 'cabo_counter-game_data',
|
||||
bytes: bytes,
|
||||
ext: 'json',
|
||||
mimeType: MimeType.json,
|
||||
@@ -123,6 +123,27 @@ class LocalStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the file picker to save a single game session as a JSON file.
|
||||
static Future<bool> exportSingleGameSession(GameSession session) async {
|
||||
final jsonString = json.encode(session.toJson());
|
||||
try {
|
||||
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
||||
final result = await FileSaver.instance.saveAs(
|
||||
name: 'cabo_counter-game_${session.id.substring(0, 7)}',
|
||||
bytes: bytes,
|
||||
ext: 'json',
|
||||
mimeType: MimeType.json,
|
||||
);
|
||||
print(
|
||||
'[local_storage_service.dart] Die Spieldaten der Session wurden exportiert. Dateipfad: $result');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print(
|
||||
'[local_storage_service.dart] Fehler beim Exportieren der Spieldaten der Session. Exception: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the file picker to import a JSON file and loads the game data from it.
|
||||
static Future<ImportStatus> importJsonFile() async {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:cabo_counter/data/game_manager.dart';
|
||||
import 'package:cabo_counter/data/game_session.dart';
|
||||
import 'package:cabo_counter/l10n/app_localizations.dart';
|
||||
import 'package:cabo_counter/services/local_storage_service.dart';
|
||||
import 'package:cabo_counter/utility/custom_theme.dart';
|
||||
import 'package:cabo_counter/views/create_game_view.dart';
|
||||
import 'package:cabo_counter/views/graph_view.dart';
|
||||
@@ -192,14 +193,15 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
||||
},
|
||||
),
|
||||
CupertinoListTile(
|
||||
title:
|
||||
Text(AppLocalizations.of(context).export_game,
|
||||
style: const TextStyle(
|
||||
color: Colors.white30,
|
||||
)),
|
||||
backgroundColorActivated:
|
||||
CustomTheme.backgroundColor,
|
||||
),
|
||||
title: Text(
|
||||
AppLocalizations.of(context).export_game,
|
||||
),
|
||||
backgroundColorActivated:
|
||||
CustomTheme.backgroundColor,
|
||||
onTap: () {
|
||||
LocalStorageService.exportSingleGameSession(
|
||||
widget.gameSession);
|
||||
}),
|
||||
],
|
||||
)
|
||||
],
|
||||
|
||||
@@ -140,7 +140,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
),
|
||||
onPressed: () async {
|
||||
final success =
|
||||
await LocalStorageService.exportJsonFile();
|
||||
await LocalStorageService.exportGameData();
|
||||
if (!success && context.mounted) {
|
||||
showCupertinoDialog(
|
||||
context: context,
|
||||
|
||||
@@ -2,7 +2,7 @@ name: cabo_counter
|
||||
description: "Mobile app for the card game Cabo"
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.3.7+323
|
||||
version: 0.3.7+325
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.4
|
||||
|
||||
Reference in New Issue
Block a user