initialize method

Future<void> initialize({
  1. required String apiKey,
  2. required String projectId,
  3. bool isProduction = true,
  4. bool isDebug = false,
})

Initialize the In-App Messages SDK

Must be called before using any other methods.

Parameters:

  • apiKey: Your PushPushGo API key
  • projectId: Your PushPushGo project ID
  • isProduction: Use production environment (default: true)
  • isDebug: Enable debug logging (default: false)

Implementation

Future<void> initialize({
  required String apiKey,
  required String projectId,
  bool isProduction = true,
  bool isDebug = false,
}) async {
  if (_isInitialized) {
    log('PPGInAppMessages: Already initialized');
    return;
  }

  try {
    await InAppMessagesChannel.invokeMethod(
      method: InAppMethod.initialize,
      arguments: {
        'apiKey': apiKey,
        'projectId': projectId,
        'isProduction': isProduction,
        'isDebug': isDebug,
      },
    );
    _isInitialized = true;
    log('PPGInAppMessages: Initialized successfully');

    // Process any buffered route from NavigatorObserver
    if (_pendingRoute != null) {
      await onRouteChanged(_pendingRoute!);
      _pendingRoute = null;
    }
  } catch (e) {
    log('PPGInAppMessages: Initialization failed - $e');
    rethrow;
  }
}