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 createState() => _Wolf3dAppState(); } class _Wolf3dAppState extends State with WidgetsBindingObserver { Future? _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 _ensureAudioShutdown() { final Future? existing = _shutdownFuture; if (existing != null) { return existing; } final Future 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); } }