initialize method

  1. @override
Future<bool> initialize()
override

Completes when the plugin's service worker has been registered and its event listeners attached.

Initialisation starts automatically when the plugin registers, so awaiting this is optional — notifications posted beforehand are queued until it completes. Await it when you need to know whether notifications are actually available:

if (await JsNotificationsPlatform.instance.initialize()) {
  // service worker registered — notifications can be shown
}

Returns false when service workers are unsupported (an insecure context — neither https nor localhost — or an unsupported browser) or registration failed. Failures are logged, never thrown. Idempotent.

Implementation

@override
Future<bool> initialize() => _initFuture;