Skip to content

Setting Up an App Initializer

What you'll learn

  • Generating pre-launch and post-launch initializers
  • Understanding the two-phase initialization pattern
  • Wiring initializers into your app's bootstrap sequence
  • Creating custom initializers for your own SDKs

Prerequisites

Step 1: Generate an Initializer

bash
archipelago generate initializer_skeleton

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • initializerTypepre_launch or post_launch
  • initializerName — e.g., Analytics, Payment, FeatureFlags

Or use a config file:

json
{
  "appName": "MyApp",
  "initializerType": "pre_launch",
  "initializerName": "Analytics"
}
bash
archipelago generate initializer_skeleton --config init_config.json

Step 2: Understand the Generated Structure

lib/src/
└── initializers/
    └── analytics_initializer.dart    # Pre-launch or post-launch initializer

The generated file extends the standard Initializer base class:

dart
class AnalyticsInitializer extends Initializer {
  @override
  Future<void> initialize() async {
    // Your initialization logic here
  }
}

Step 3: Pre-Launch vs Post-Launch

The initializerType determines when the initializer runs:

TypeWhen it RunsUse For
pre_launchBefore the first frame renders (blocking)DI setup, route registration, critical SDKs
post_launchAfter the first frame renders (non-blocking)Analytics, feature flags, remote config

Pre-launch initializers block the splash screen. Keep them fast. Post-launch initializers run in the background after your app is already visible.

Step 4: Wire Into Bootstrap

Register the initializer in your app's bootstrap sequence:

dart
// Pre-launch initializers run before app starts
final preLaunchInitializers = [
  DiInitializer(),
  RouterInitializer(),
  AnalyticsInitializer(), // Your generated initializer
];

// Post-launch initializers run after first frame
final postLaunchInitializers = [
  RemoteConfigInitializer(),
  FeatureFlagInitializer(),
];

Step 5: Add Your Logic

Fill in the generated initializer with your actual setup code:

dart
class AnalyticsInitializer extends Initializer {
  @override
  Future<void> initialize() async {
    final analytics = GetIt.I<AnalyticsClient>();
    await analytics.init();
    await analytics.identifyUser();
  }
}

Common Customizations

CustomizationHow
Add dependenciesInject via GetIt in initialize()
Add error handlingWrap in try/catch, log to monitoring
Add timeoutUse Future.timeout() for pre-launch initializers
Chain initializersReturn values via shared DI container

Next Steps

Built by Banua Coder