initialize method

Future<void> initialize({
  1. required InboxApiClient client,
})

Initialize with a client reference that handles all inbox API calls.

Implementation

Future<void> initialize({required InboxApiClient client}) async {
  _client = client;
  if (_initialized) {
    // Already registered as an observer — skip re-registration to avoid
    // didChangeAppLifecycleState firing multiple times per lifecycle event.
    debugPrint('InboxService already initialized, updating client only');
    return;
  }
  _initialized = true;

  // Register lifecycle observer to refresh when app returns to foreground
  WidgetsBinding.instance.addObserver(this);

  // Restore cached state from storage
  await _restoreCachedState();

  debugPrint('InboxService initialized');
}