|
|
@@ -9,6 +9,7 @@ import 'utils/score_manager.dart';
|
|
|
import 'utils/google_play_games_manager.dart';
|
|
|
import 'utils/locale_manager.dart';
|
|
|
import 'utils/app_lifecycle_manager.dart';
|
|
|
+import 'game/audio/audio_manager.dart';
|
|
|
|
|
|
void main() async {
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
@@ -16,6 +17,9 @@ void main() async {
|
|
|
await ScoreManager.initialize();
|
|
|
await LocaleManager.init();
|
|
|
|
|
|
+ // Initialize audio manager early
|
|
|
+ await AudioManager().initialize();
|
|
|
+
|
|
|
// Initialize Google Play Games (silent init, don't require sign-in)
|
|
|
await GooglePlayGamesManager.instance.initialize();
|
|
|
|
|
|
@@ -32,7 +36,7 @@ class ZenTapApp extends StatefulWidget {
|
|
|
State<ZenTapApp> createState() => _ZenTapAppState();
|
|
|
}
|
|
|
|
|
|
-class _ZenTapAppState extends State<ZenTapApp> {
|
|
|
+class _ZenTapAppState extends State<ZenTapApp> with WidgetsBindingObserver {
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
@@ -40,13 +44,32 @@ class _ZenTapAppState extends State<ZenTapApp> {
|
|
|
LocaleManager.setLocaleChangeCallback(() {
|
|
|
setState(() {});
|
|
|
});
|
|
|
+ // Add observer for app lifecycle
|
|
|
+ WidgetsBinding.instance.addObserver(this);
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void dispose() {
|
|
|
+ // Remove observer
|
|
|
+ WidgetsBinding.instance.removeObserver(this);
|
|
|
+ // Dispose audio manager when app is being terminated
|
|
|
+ AudioManager().dispose();
|
|
|
+ // Dispose app lifecycle manager
|
|
|
+ AppLifecycleManager.instance.dispose();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
+ @override
|
|
|
+ void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
+ super.didChangeAppLifecycleState(state);
|
|
|
+
|
|
|
+ // Handle app termination
|
|
|
+ if (state == AppLifecycleState.detached) {
|
|
|
+ // App is being completely terminated, dispose audio immediately
|
|
|
+ AudioManager().dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return MaterialApp(
|