88050dbc7d
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
66 lines
1.6 KiB
Dart
66 lines
1.6 KiB
Dart
library;
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:wolf_3d_flutter/wolf_3d_flutter.dart';
|
|
|
|
/// Minimal app shell that binds a prepared [Wolf3dFlutterEngine] instance to
|
|
/// host screens.
|
|
class Wolf3dApp extends StatefulWidget {
|
|
/// Shared initialized facade that owns game data, input, and audio services.
|
|
final Wolf3dFlutterEngine engine;
|
|
|
|
const Wolf3dApp({
|
|
super.key,
|
|
required this.engine,
|
|
});
|
|
|
|
@override
|
|
State<Wolf3dApp> createState() => _Wolf3dAppState();
|
|
}
|
|
|
|
class _Wolf3dAppState extends State<Wolf3dApp> with WidgetsBindingObserver {
|
|
Future<void>? _shutdownFuture;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
unawaited(_ensureAudioShutdown());
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.detached) {
|
|
unawaited(_ensureAudioShutdown());
|
|
}
|
|
}
|
|
|
|
Future<void> _ensureAudioShutdown() {
|
|
final Future<void>? existing = _shutdownFuture;
|
|
if (existing != null) {
|
|
return existing;
|
|
}
|
|
|
|
final Future<void> shutdown = widget.engine.shutdownAudio();
|
|
_shutdownFuture = shutdown;
|
|
return shutdown;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return widget.engine.availableGames.isEmpty
|
|
? NoGameDataScreen(
|
|
configuredDataDirectory: widget.engine.configuredDataDirectory,
|
|
)
|
|
: GameScreen(wolf3d: widget.engine);
|
|
}
|
|
}
|