From 341fa5875f274ece04c1e3d54a77ac51e20b8765 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Tue, 11 Oct 2022 20:33:56 +1100 Subject: [PATCH] [flutter_local_notifications] lookup callback after Flutter engine is created (#1751) * lookup callback after Flutter engine is created * Google Java Format * add changelog entry for handle detaching from engine * update to use static string defined for permission request in progress error message Co-authored-by: github-actions <> --- flutter_local_notifications/CHANGELOG.md | 5 +++++ .../ActionBroadcastReceiver.java | 15 +++++++++------ .../FlutterLocalNotificationsPlugin.java | 2 +- flutter_local_notifications/pubspec.yaml | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index 84dfe9fbe..436a52015 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,3 +1,8 @@ +# [12.0.2] + +* [Android] changed callback lookup for notification actions to take place after Flutter engine to ensure callback cache has been initialised to find the callback. This is a follow-up to changes done in 12.0.1 in trying to address issue [1721](https://github.com/MaikuB/flutter_local_notifications/issues/1721) +* [Android] updated plugin to clean up resources after it is detached from Flutter engine. Thanks to PR from [Simon Ser](https://github.com/emersion) + # [12.0.1+1] * Updated readme to indicate that the `timezone` package should be added as a direct dependency according to [this official lint rule](https://dart-lang.github.io/linter/lints/depend_on_referenced_packages.html) diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/ActionBroadcastReceiver.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/ActionBroadcastReceiver.java index 971432634..d9c93acd2 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/ActionBroadcastReceiver.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/ActionBroadcastReceiver.java @@ -71,12 +71,6 @@ private void startEngine(Context context) { return; } - FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle(); - if (dispatcherHandle == null) { - Log.w(TAG, "Callback information could not be retrieved"); - return; - } - FlutterInjector injector = FlutterInjector.instance(); FlutterLoader loader = injector.flutterLoader(); @@ -84,6 +78,15 @@ private void startEngine(Context context) { loader.ensureInitializationComplete(context, null); engine = new FlutterEngine(context); + + /// This lookup needs to be done after creating an instance of `FlutterEngine` or lookup may + // fail + FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle(); + if (dispatcherHandle == null) { + Log.w(TAG, "Callback information could not be retrieved"); + return; + } + DartExecutor dartExecutor = engine.getDartExecutor(); initializeEventChannel(dartExecutor); diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java index 8dde95dda..9c5e6b882 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java @@ -1648,7 +1648,7 @@ private void cancelAllNotifications(Result result) { public void requestPermission(@NonNull PermissionRequestListener callback) { if (permissionRequestInProgress) { - callback.fail("Another permission request is already in progress"); + callback.fail(PERMISSION_REQUEST_IN_PROGRESS_ERROR_MESSAGE); return; } diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index f5b466daa..35f90c07c 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_local_notifications description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform. -version: 12.0.1+1 +version: 12.0.2 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues