ensureFirebaseInitializedForBackground static method
Initializes Firebase in a background isolate when needed.
Pass options from your generated firebase_options.dart (evaluated inside
the background handler). configureMeSendFirebaseBackgroundInit in main
alone is not sufficient — statics are not shared across isolates.
Implementation
static Future<bool> ensureFirebaseInitializedForBackground({
FirebaseOptions? options,
}) async {
WidgetsFlutterBinding.ensureInitialized();
if (Firebase.apps.isNotEmpty) {
return true;
}
final resolved = options ?? _meSendFirebaseBackgroundOptions;
if (resolved == null) {
meherySenderLog(
'Firebase init skipped — pass options to meSendHandleBackgroundRemoteMessage('
'message, options: DefaultFirebaseOptions.currentPlatform) from a host '
'@pragma(\'vm:entry-point\') top-level handler. '
'configureMeSendFirebaseBackgroundInit in main() does not apply to the '
'background isolate. See README §2.3.',
tag: 'Push|background',
);
return false;
}
await Firebase.initializeApp(options: resolved);
return true;
}