m7c: brand splash instead of the white startup screen

- LaunchTheme/NormalTheme on #05070A (was the stock light theme + white
  windowBackground) and the Android 12 splash API in values-v31
- splash icon is a padded 512x512 canvas: Android masks everything outside the
  inner 192dp of the 288dp icon area, which clipped the wordmark at the top;
  the icon plate is set to the icon navy
- Flutter splash (lib/src/ui/splash_screen.dart): logo pulses (scale 0.96-1.04,
  opacity 0.72-1.0, 1100 ms) plus a thin progress line, min 700 ms measured
  from the first Flutter frame
- boot work (session, FFI library, ad SDK) now runs after the first frame and
  the game fades in over the splash: no blocking work before the first frame
- numbers (Redmi Note 10, API 31): debug 3053 ms, profile/AOT 2040 ms on the
  first start, 850-960 ms on later cold starts, ready log ~1030 ms
- fixed: top-level Stopwatch only started on first access (Dart lazily
  initialises top-level finals), so the boot log always showed 0 ms
- tools/device/startup.sh measures cold start + boot log; testing.md documents
  the splash chain and the MIUI release-install trap
This commit is contained in:
2026-10-25 02:34:09 +02:00
parent 94c3ef0f63
commit 92b5ef16cb
17 changed files with 362 additions and 89 deletions
+129 -62
View File
@@ -10,9 +10,18 @@ import 'src/native/native_match.dart';
import 'src/net/api_client.dart';
import 'src/net/match_session.dart';
import 'src/net/offline_queue.dart';
import 'src/ui/splash_screen.dart';
import 'src/ui/widgets.dart';
void main() => runApp(const IronArcApp());
/// Started in `main()`, so the boot log line covers the whole cold start
/// (engine, Dart isolate and native match load). Must be initialised eagerly -
/// a top-level `final` would only start on first access.
final Stopwatch _bootWatch = Stopwatch();
void main() {
_bootWatch.start();
runApp(const IronArcApp());
}
class IronArcApp extends StatelessWidget {
const IronArcApp({super.key});
@@ -39,18 +48,52 @@ class MatchScreen extends StatefulWidget {
class _MatchScreenState extends State<MatchScreen> {
static const _baseUrl = 'http://127.0.0.1:8080';
/// Minimum time the splash stays up, so even a warm start shows the brand
/// instead of a single-frame flicker.
static const _minSplash = Duration(milliseconds: 700);
int _seed = 42;
late final ApiClient _api = ApiClient(baseUrl: _baseUrl);
late final OfflineQueue _queue = OfflineQueue();
late final AdsService _ads = AdsService();
late final MatchSession _session =
MatchSession(client: _api, queue: _queue, deviceId: 'pending');
late IronArcGame _game = _buildGame();
/// Null while booting. Constructing a game loads the native match library,
/// which must not block the first frame - that used to be the white screen.
IronArcGame? _game;
bool _splashGone = false;
@override
void initState() {
super.initState();
_initSession();
// Boot after the first frame so the splash is painted before any blocking
// work (FFI library load, shared preferences, ad SDK).
WidgetsBinding.instance.addPostFrameCallback((_) => _bootstrap());
}
/// Session, native match and ad SDK - all while the splash is on screen.
Future<void> _bootstrap() async {
// Measured from the first Flutter frame, so the pulse is always visible
// even when the engine took seconds to start (debug builds, cold JIT).
final splashStart = Stopwatch()..start();
await _initSession();
final game = _buildGame();
if (!mounted) return;
// Keep the brand moment on screen even when everything loads instantly.
final left = _minSplash - splashStart.elapsed;
if (left > Duration.zero) await Future<void>.delayed(left);
if (!mounted) return;
setState(() => _game = game);
// Fade out over the already-built match, then drop the splash from the tree.
await Future<void>.delayed(const Duration(milliseconds: 320));
if (!mounted) return;
setState(() => _splashGone = true);
debugPrint('iron_arc: ready after ${_bootWatch.elapsedMilliseconds} ms');
_ads.initialize();
}
@@ -109,7 +152,9 @@ class _MatchScreenState extends State<MatchScreen> {
}
void _playReplay() {
final json = _game.replayJson();
final game = _game;
if (game == null) return;
final json = game.replayJson();
debugPrint('iron_arc: replay tapped, ${json.length} bytes');
if (json.isEmpty) {
_toast('Kein Replay vorhanden');
@@ -208,70 +253,92 @@ class _MatchScreenState extends State<MatchScreen> {
@override
Widget build(BuildContext context) {
final game = _game;
return Scaffold(
backgroundColor: const Color(0xFF05070A),
body: SafeArea(
child: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 0),
child: Column(
children: [
ValueListenableBuilder<HudState>(
valueListenable: _game.hud,
builder: (context, hud, _) => Hud(hud: hud),
),
const SizedBox(height: 6),
AnimatedBuilder(
animation: _session,
builder: (context, _) =>
StatusBar(session: _session, onSettings: _openSettings),
),
],
backgroundColor: SplashScreen.background,
body: Stack(
children: [
// The match only exists once the native library and session are up;
// until then the pulsing splash covers the whole window.
if (game != null) _buildMatch(game),
if (!_splashGone)
Positioned.fill(
child: AnimatedOpacity(
opacity: game == null ? 1 : 0,
duration: const Duration(milliseconds: 280),
curve: Curves.easeOut,
child: const SplashScreen(),
),
),
// Play area: gestures only affect the game, never the controls.
Expanded(
child: Stack(
children: [
Positioned.fill(child: GameWidget(key: ValueKey(_game), game: _game)),
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanStart: (d) => _game.beginAim(d.localPosition),
onPanUpdate: (d) => _game.updateAim(d.localPosition),
onPanEnd: (_) => _game.releaseAim(),
),
),
Positioned(
left: 16,
right: 16,
bottom: 8,
child: ValueListenableBuilder<HudState>(
valueListenable: _game.hud,
builder: (context, hud, _) => hud.isFinished
? GameOver(hud: hud, onRestart: _restart)
: HintBubble(hud: hud),
),
),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
child: AnimatedBuilder(
animation: _session,
builder: (context, _) => Controls(
session: _session,
onOnline: _startOnline,
onReplay: _playReplay,
onFlush: _flushQueue,
onAd: _showRewardedAd,
],
),
);
}
/// HUD, canvas and controls of a running match.
Widget _buildMatch(IronArcGame game) {
return SafeArea(
child: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 0),
child: Column(
children: [
ValueListenableBuilder<HudState>(
valueListenable: game.hud,
builder: (context, hud, _) => Hud(hud: hud),
),
const SizedBox(height: 6),
AnimatedBuilder(
animation: _session,
builder: (context, _) =>
StatusBar(session: _session, onSettings: _openSettings),
),
],
),
),
// Play area: gestures only affect the game, never the controls.
Expanded(
child: Stack(
children: [
Positioned.fill(
child: GameWidget(key: ValueKey(game), game: game)),
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onPanStart: (d) => game.beginAim(d.localPosition),
onPanUpdate: (d) => game.updateAim(d.localPosition),
onPanEnd: (_) => game.releaseAim(),
),
),
Positioned(
left: 16,
right: 16,
bottom: 8,
child: ValueListenableBuilder<HudState>(
valueListenable: game.hud,
builder: (context, hud, _) => hud.isFinished
? GameOver(hud: hud, onRestart: _restart)
: HintBubble(hud: hud),
),
),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 8),
child: AnimatedBuilder(
animation: _session,
builder: (context, _) => Controls(
session: _session,
onOnline: _startOnline,
onReplay: _playReplay,
onFlush: _flushQueue,
onAd: _showRewardedAd,
),
),
],
),
),
],
),
);
}
+75
View File
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
/// Brand splash shown while the native match library, the session and the
/// ad SDK boot. The logo pulses so a cold start reads as "loading" instead of
/// a frozen screen - the native launch theme uses the same colour and image,
/// so the handover from the Android window to Flutter is invisible.
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
/// Canvas colour of the game; the Android launch theme uses the same value.
static const background = Color(0xFF05070A);
static const accent = Color(0xFFFF8A3D);
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
late final AnimationController _pulse = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1100),
)..repeat(reverse: true);
late final Animation<double> _scale = Tween<double>(begin: 0.96, end: 1.04)
.animate(CurvedAnimation(parent: _pulse, curve: Curves.easeInOut));
late final Animation<double> _opacity = Tween<double>(begin: 0.72, end: 1.0)
.animate(CurvedAnimation(parent: _pulse, curve: Curves.easeInOut));
@override
void dispose() {
_pulse.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ColoredBox(
color: SplashScreen.background,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
FadeTransition(
opacity: _opacity,
child: ScaleTransition(
scale: _scale,
child: Image.asset(
'assets/logo_mark.png',
width: 220,
filterQuality: FilterQuality.medium,
semanticLabel: 'Iron Arc',
),
),
),
const SizedBox(height: 28),
// Thin indeterminate bar: tells the player the app is working,
// not hung. Kept subtle so the logo stays the focus.
SizedBox(
width: 140,
child: ClipRRect(
borderRadius: BorderRadius.circular(2),
child: LinearProgressIndicator(
minHeight: 2,
color: SplashScreen.accent,
backgroundColor: const Color(0xFF16202E),
),
),
),
],
),
),
);
}
}