Implemented life cycle listener
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:cabo_counter/data/game_session.dart';
|
||||
import 'package:cabo_counter/utility/apptheme.dart';
|
||||
import 'package:cabo_counter/utility/globals.dart';
|
||||
import 'package:cabo_counter/utility/local_storage_service.dart';
|
||||
import 'package:cabo_counter/views/main_menu_view.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -6,7 +8,7 @@ import 'package:flutter/cupertino.dart';
|
||||
void main() {
|
||||
/// FIXME Just for Debugging
|
||||
/// Fills the game list with some test data.
|
||||
/*Globals.addGameSession(GameSession(
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Spiel am 27.02.2025',
|
||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||
gameHasPointLimit: true));
|
||||
@@ -39,13 +41,39 @@ void main() {
|
||||
gameTitle: '5 Namen max length',
|
||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
||||
gameHasPointLimit: false));
|
||||
*/
|
||||
|
||||
runApp(const App());
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
class App extends StatefulWidget {
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _AppState();
|
||||
}
|
||||
|
||||
class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
LocalStorageService.loadGameSessions();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.paused ||
|
||||
state == AppLifecycleState.detached) {
|
||||
LocalStorageService.saveGameSessions();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
LocalStorageService.loadGameSessions();
|
||||
@@ -64,8 +92,4 @@ class App extends StatelessWidget {
|
||||
home: const MainMenuView(),
|
||||
);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
LocalStorageService.saveGameSessions();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user