From f34542d53549a4084a51de1deed5ad508caf69dd Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 10 Oct 2026 16:35:28 +0200 Subject: [PATCH] Add flutter_local_notifications and its platform setup --- android/app/build.gradle | 6 +++ android/app/src/main/AndroidManifest.xml | 9 ++++ ios/Runner/AppDelegate.swift | 30 +++++++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 52 ++++++++++++++++--- pubspec.yaml | 1 + windows/flutter/generated_plugins.cmake | 1 + 7 files changed, 95 insertions(+), 6 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index f81c24ede..be6c05e4a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -33,6 +33,8 @@ android { compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 + // Required by flutter_local_notifications + coreLibraryDesugaringEnabled true } @@ -80,3 +82,7 @@ kotlin { flutter { source '../..' } + +dependencies { + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4' +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index fe564095e..9e65ff240 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -110,6 +110,15 @@ + + + + Bool { + // Lets notifications show in the foreground and delivers action responses + UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate return super.application(application, didFinishLaunchingWithOptions: launchOptions) } + // A notification action is handled by the main isolate, but the plugin + // completes the response right away and iOS suspends the app again. + // Keep it running briefly so the action is processed now. + override func userNotificationCenter( + _ center: UNUserNotificationCenter, + didReceive response: UNNotificationResponse, + withCompletionHandler completionHandler: @escaping () -> Void + ) { + var task: UIBackgroundTaskIdentifier = .invalid + task = UIApplication.shared.beginBackgroundTask { + UIApplication.shared.endBackgroundTask(task) + task = .invalid + } + DispatchQueue.main.asyncAfter(deadline: .now() + 10) { + if task != .invalid { + UIApplication.shared.endBackgroundTask(task) + task = .invalid + } + } + super.userNotificationCenter( + center, didReceive: response, withCompletionHandler: completionHandler) + } + func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) { + // Notification actions run in a separate engine, which needs the plugins too + FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { registry in + GeneratedPluginRegistrant.register(with: registry) + } GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry) guard let registrar = engineBridge.pluginRegistry.registrar( diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 316227cfd..fd9b51dc2 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import connectivity_plus import device_info_plus import dynamic_color import file_selector_macos +import flutter_local_notifications import flutter_secure_storage_darwin import flutter_timezone import package_info_plus @@ -23,6 +24,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FlutterSecureStorageDarwinPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageDarwinPlugin")) FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 54448efbf..26ab56331 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -277,10 +277,10 @@ packages: dependency: "direct main" description: name: connectivity_plus - sha256: d7749fd36d8b404a4935612b94eca7c3ce3705377ab678e24ff2a4301436f741 + sha256: "762c99f890ca8bf87f7337236f99edd42793843bc6c3631da294a76653a54bd0" url: "https://pub.dev" source: hosted - version: "7.3.2" + version: "7.3.1" connectivity_plus_platform_interface: dependency: "direct dev" description: @@ -349,10 +349,10 @@ packages: dependency: transitive description: name: dbus - sha256: f7db8504e715b835f5ebe5fe74604ccd961d504c73389a5d8e81bafc2e2f3612 + sha256: a48d5da28e89bd02196e80d81ed8d7954923d00a0f4a68cc20b575038f023383 url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.7.15" device_info_plus: dependency: transitive description: @@ -547,6 +547,46 @@ packages: url: "https://pub.dev" source: hosted version: "6.0.0" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + sha256: "357be7ff996dc272e2037c69c1bdd5d1bd21172219d55f8bd2e11aeea602e6d3" + url: "https://pub.dev" + source: hosted + version: "22.3.1" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + sha256: "9ca97e63776f29ab1b955725c09999fc2c150523269db150c39274f2a43c5a8b" + url: "https://pub.dev" + source: hosted + version: "8.0.1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + sha256: "43c3761d916c9bd3d5c7ebbc44d82f4990329840c0c5d62ad5260cc1b5d399bd" + url: "https://pub.dev" + source: hosted + version: "12.2.0" + flutter_local_notifications_web: + dependency: transitive + description: + name: flutter_local_notifications_web + sha256: "516afaf97a2d1e67a036c6617321b00d205d72f7a67b6eccf936cd565f985878" + url: "https://pub.dev" + source: hosted + version: "1.0.0" + flutter_local_notifications_windows: + dependency: transitive + description: + name: flutter_local_notifications_windows + sha256: "6f43bdd03b171b7a90f22647506fea33e2bb12294b7c7c7a3d690e960a382945" + url: "https://pub.dev" + source: hosted + version: "3.1.1" flutter_localizations: dependency: "direct main" description: flutter @@ -1073,10 +1113,10 @@ packages: dependency: transitive description: name: nm - sha256: "2ae480aa3379716b8bb58dfebb168e2919394c92b629efaaa0baaa5d140786e6" + sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.5.0" objective_c: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 60b723881..fffd1406f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -83,6 +83,7 @@ dependencies: flutter_timezone: ^5.1.0 timezone: ^0.11.1 material_ui: ^1.4.0 + flutter_local_notifications: ^22.3.1 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 0df1af527..1388064da 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -13,6 +13,7 @@ list(APPEND FLUTTER_PLUGIN_LIST ) list(APPEND FLUTTER_FFI_PLUGIN_LIST + flutter_local_notifications_windows flutter_zxing jni )