app-startup-and-bootstrap

Enforces ordered Flutter main() cold-launch sequence with error handlers, DI bootstrap, and deferred warm-up.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/zakariaf/NearlyStop --skill app-startup-and-bootstrap-zakariaf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: app-startup-and-bootstrap
Source: https://github.com/zakariaf/NearlyStop/tree/main/.claude/skills/app-startup-and-bootstrap
Command: npx skills add https://github.com/zakariaf/NearlyStop --skill app-startup-and-bootstrap-zakariaf

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Flutter apps often crash silently at cold start, flash the wrong theme on the first frame, block the UI with slow warm-up work, or hide real errors behind zones and retry loops. This Skill enforces a fixed, ordered main() launch sequence so failures surface loudly and the first frame paints correctly. ## Core Features & Use Cases - Ordered launch sequence: Installs a crash-log sink plus FlutterError.onError and PlatformDispatcher.onError before any code that can throw, with exactly two handlers and no runZonedGuarded. - Composition-root DI: Builds real infrastructure (database, settings, notifications) in a bootstrap() function and injects it via ProviderScope overrideWithValue over throwing placeholder providers, so forgotten wiring fails loudly. - First-frame correctness: Reads theme, locale, and settings before runApp, defers warm-up to addPostFrameCallback, and flushes durable state on background via a single WidgetsBindingObserver. - Use Case: When editing lib/main.dart or bootstrap.dart in a Flutter app, apply this Skill to reorder startup code so a database migration never leaves the user staring at a blank window and a crash on frame one is always recorded. ## Quick Start Review my lib/main.dart and bootstrap.dart and reorder the startup sequence so error handlers install first, settings load before runApp, and warm-up is deferred past the first frame.

Frequently Asked Questions about app-startup-and-bootstrap

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Flutter main() for cold start?

Call WidgetsFlutterBinding.ensureInitialized(), open a crash-log sink, install FlutterError.onError and PlatformDispatcher.onError, then run a bootstrap() that opens the database and reads settings before calling runApp. Defer all warm-up work to addPostFrameCallback so it never blocks the first frame.

Do I need runZonedGuarded with FlutterError.onError?

No. FlutterError.onError covers build, layout, and paint errors while PlatformDispatcher.onError covers uncaught async errors, so two handlers cover every path. runZonedGuarded only matters for crash SDKs like Sentry and otherwise adds a zone-mismatch footgun.

How do I inject dependencies with Riverpod at app startup?

Define throwing placeholder providers in feature code, build real implementations in a composition-root bootstrap(), and inject them with overrideWithValue on the root ProviderScope. A forgotten wiring then throws UnimplementedError at startup instead of returning null.

Why does my Flutter app flash the wrong theme on launch?

The theme and locale are being read after runApp, so the first frame paints with defaults before the real values load. Read settings synchronously before runApp; a handful of database rows costs under 10ms and guarantees the first frame is correct.

Why does PlatformDispatcher.onError need to return true?

Returning false routes the error to the embedder fallback, where the process may exit or hang. Return true unconditionally and get debug visibility from debugPrint under kDebugMode instead of from the return value.

When should I flush app state to disk in Flutter?

Flush pending writes when the app reaches inactive or paused lifecycle states, because the OS can kill a backgrounded app with no further callback. Use one root WidgetsBindingObserver that calls flush() on repositories via ref.read, and re-read time-sensitive state on resumed.