init static method

Future<void> init({
  1. String? appId,
  2. String? appName,
  3. String? androidIcon,
  4. String? windowsIconPath,
  5. bool showInForeground = true,
})

Registers with the OS, starts receiving taps and re-arms Dart-side schedules. Idempotent.

Implementation

static Future<void> init({String? appId, String? appName, String? androidIcon, String? windowsIconPath, bool showInForeground = true}) async {
  _listen();
  if (_initialized) return;
  _initialized = true;
  final String id = appId ?? (UPackage.isReady ? UPackage.packageName : "u.app");
  if (kIsWeb) {
    UNotificationWeb.onEvent = _controller.add;
  } else {
    await _call<void>("init", <String, Object?>{
      "appId": id,
      "appName": appName ?? (UPackage.isReady && UPackage.appName.isNotEmpty ? UPackage.appName : id),
      // Windows toast activation needs a stable CLSID per app.
      "guid": UUUID.uuidV5(UUUID.namespaceUrl, "u.notify.$id"),
      "icon": androidIcon,
      "iconPath": windowsIconPath,
      "foreground": showInForeground,
    });
  }
  await _rearm();
}