Refactoring
This commit is contained in:
@@ -27,4 +27,4 @@ class GameManager extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
final globals = GameManager();
|
||||
final gameManager = GameManager();
|
||||
|
||||
@@ -19,7 +19,7 @@ class LocalStorageService {
|
||||
/// Writes the game session list to a JSON file and returns it as string.
|
||||
static String getJsonFile() {
|
||||
final jsonFile =
|
||||
globals.gameList.map((session) => session.toJson()).toList();
|
||||
gameManager.gameList.map((session) => session.toJson()).toList();
|
||||
return json.encode(jsonFile);
|
||||
}
|
||||
|
||||
@@ -63,14 +63,14 @@ class LocalStorageService {
|
||||
|
||||
if (!await validateJsonSchema(jsonString)) {
|
||||
logger.w('Die Datei konnte nicht validiert werden');
|
||||
globals.gameList = [];
|
||||
gameManager.gameList = [];
|
||||
return false;
|
||||
}
|
||||
logger.d('Die gefundene Datei hat Inhalt');
|
||||
logger.d('Die gefundene Datei wurde erfolgreich validiert');
|
||||
final jsonList = json.decode(jsonString) as List<dynamic>;
|
||||
|
||||
globals.gameList = jsonList
|
||||
gameManager.gameList = jsonList
|
||||
.map((jsonItem) =>
|
||||
GameSession.fromJson(jsonItem as Map<String, dynamic>))
|
||||
.toList();
|
||||
@@ -80,7 +80,7 @@ class LocalStorageService {
|
||||
} catch (e) {
|
||||
logger.e('Fehler beim Laden der Spieldaten:\n$e',
|
||||
error: 'JSON nicht geladen');
|
||||
globals.gameList = [];
|
||||
gameManager.gameList = [];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class LocalStorageService {
|
||||
return false;
|
||||
}
|
||||
final jsonData = json.decode(jsonString) as List<dynamic>;
|
||||
globals.gameList = jsonData
|
||||
gameManager.gameList = jsonData
|
||||
.map((jsonItem) =>
|
||||
GameSession.fromJson(jsonItem as Map<String, dynamic>))
|
||||
.toList();
|
||||
@@ -172,7 +172,7 @@ class LocalStorageService {
|
||||
|
||||
static Future<bool> deleteAllGames() async {
|
||||
try {
|
||||
globals.gameList.clear();
|
||||
gameManager.gameList.clear();
|
||||
await saveGameSessions();
|
||||
logger.i('Alle Runden wurden erfolgreich gelöscht.');
|
||||
return true;
|
||||
|
||||
@@ -290,7 +290,7 @@ class _CreateGameState extends State<CreateGame> {
|
||||
caboPenalty: Globals.caboPenalty,
|
||||
isPointsLimitEnabled: selectedMode!,
|
||||
);
|
||||
globals.addGameSession(gameSession);
|
||||
gameManager.addGameSession(gameSession);
|
||||
LocalStorageService.saveGameSessions();
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacement(
|
||||
|
||||
@@ -26,7 +26,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
_isLoading = false;
|
||||
});
|
||||
});
|
||||
globals.addListener(_updateView);
|
||||
gameManager.addListener(_updateView);
|
||||
}
|
||||
|
||||
void _updateView() {
|
||||
@@ -39,7 +39,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
LocalStorageService.loadGameSessions();
|
||||
|
||||
return ListenableBuilder(
|
||||
listenable: globals,
|
||||
listenable: gameManager,
|
||||
builder: (context, _) {
|
||||
return CupertinoPageScaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
@@ -70,7 +70,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
child: SafeArea(
|
||||
child: _isLoading
|
||||
? const Center(child: CupertinoActivityIndicator())
|
||||
: globals.gameList.isEmpty
|
||||
: gameManager.gameList.isEmpty
|
||||
? Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center, // Oben ausrichten
|
||||
@@ -97,9 +97,9 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: globals.gameList.length,
|
||||
itemCount: gameManager.gameList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final session = globals.gameList[index];
|
||||
final session = gameManager.gameList[index];
|
||||
return Dismissible(
|
||||
key: Key(session.gameTitle),
|
||||
background: Container(
|
||||
@@ -114,7 +114,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
direction: DismissDirection.startToEnd,
|
||||
confirmDismiss: (direction) async {
|
||||
final String gameTitle =
|
||||
globals.gameList[index].gameTitle;
|
||||
gameManager.gameList[index].gameTitle;
|
||||
return await _showDeleteGamePopup(gameTitle);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
@@ -161,7 +161,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ActiveGameView(
|
||||
gameSession:
|
||||
globals.gameList[index]),
|
||||
gameManager.gameList[index]),
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
@@ -220,7 +220,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
/// This function takes an [index] as parameter and removes the game session at
|
||||
/// that index from the global game list,
|
||||
void _deleteSpecificGame(int index) {
|
||||
globals.gameList.removeAt(index);
|
||||
gameManager.gameList.removeAt(index);
|
||||
LocalStorageService.saveGameSessions();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user