From 49c487f351185c8067d0378ea896cc0fc24b4fa9 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:07:57 +1000 Subject: [PATCH] [flutter_local_notifications] removed deprecated androidAllowWhileIdle parameter and made androidScheduleMode required (#2374) * removed deprecated androidAllowWhileIdle parameter and made androidScheduleMode required * updated changelog entries on Flutter SDK bump to indicate breaking change * tweaked android breaking change --- flutter_local_notifications/CHANGELOG.md | 3 +- flutter_local_notifications/README.md | 2 +- .../flutter_local_notifications_plugin.dart | 46 ++----------------- ...roid_flutter_local_notifications_test.dart | 1 + .../ios_flutter_local_notifications_test.dart | 12 ++--- ...acos_flutter_local_notifications_test.dart | 1 + .../CHANGELOG.md | 2 +- .../CHANGELOG.md | 2 +- 8 files changed, 18 insertions(+), 51 deletions(-) diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index 410dbc1bd..02c08011b 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,6 +1,7 @@ ## [vNext] -* Bumped minimum Flutter SDK requirement to 3.13 +* **Breaking change** Bumped minimum Flutter SDK requirement to 3.13 +* [Android] **Breaking change** removed the deprecated `androidAllowWhileIdle` parameter from `zonedSchedule()` and `periodicallyShow()` methods. `androidScheduleMode` is now a required parameter ## [17.2.1+2] diff --git a/flutter_local_notifications/README.md b/flutter_local_notifications/README.md index 9fec8491d..2619472e8 100644 --- a/flutter_local_notifications/README.md +++ b/flutter_local_notifications/README.md @@ -753,7 +753,7 @@ const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.periodicallyShow(0, 'repeating title', 'repeating body', RepeatInterval.everyMinute, notificationDetails, - androidAllowWhileIdle: true); + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); ``` ### Retrieving pending notification requests diff --git a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart index d4a815ed6..ae3b0eb4c 100644 --- a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart +++ b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart @@ -301,13 +301,6 @@ class FlutterLocalNotificationsPlugin { /// platform channel in yyyy-mm-dd hh:mm:ss format. Therefore, the precision /// is at the best to the second. /// - /// The [androidAllowWhileIdle] parameter determines if the notification - /// should still be shown at the exact time even when the device is in a - /// low-power idle mode. This parameter has been deprecated and will removed - /// in a future major release in favour of the [androidScheduledMode] - /// parameter that provides the same functionality in addition to being able - /// to schedule notifications with inexact timings. - /// /// The [uiLocalNotificationDateInterpretation] is for iOS versions older /// than 10 as the APIs have limited support for time zones. With this /// parameter, it is used to determine if the scheduled date should be @@ -339,9 +332,7 @@ class FlutterLocalNotificationsPlugin { NotificationDetails notificationDetails, { required UILocalNotificationDateInterpretation uiLocalNotificationDateInterpretation, - @Deprecated('Deprecated in favor of the androidScheduleMode parameter') - bool androidAllowWhileIdle = false, - AndroidScheduleMode? androidScheduleMode, + required AndroidScheduleMode androidScheduleMode, String? payload, DateTimeComponents? matchDateTimeComponents, }) async { @@ -352,14 +343,9 @@ class FlutterLocalNotificationsPlugin { await resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>()! .zonedSchedule( - id, - title, - body, - scheduledDate, - notificationDetails.android, + id, title, body, scheduledDate, notificationDetails.android, payload: payload, - scheduleMode: _chooseScheduleMode( - androidScheduleMode, androidAllowWhileIdle), + scheduleMode: androidScheduleMode, matchDateTimeComponents: matchDateTimeComponents); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< @@ -388,18 +374,6 @@ class FlutterLocalNotificationsPlugin { /// notification will be an hour after the method has been called and /// then every hour after that. /// - /// If [androidAllowWhileIdle] is `false`, the Android `AlarmManager` APIs - /// are used to set a recurring inexact alarm that would present the - /// notification. This means that there may be delay in on when - /// notifications are displayed. If [androidAllowWhileIdle] is `true`, the - /// Android `AlarmManager` APIs are used to schedule a single notification - /// to be shown at the exact time even when the device is in a low-power idle - /// mode. After it is shown, the next one would be scheduled and this would - /// repeat. Note that this parameter has been deprecated and will removed in - /// future majorrelease in favour of the [androidScheduledMode] parameter that - /// provides the same functionality in addition to being able to schedule - /// notifications with inexact timings. - /// /// On Android, this will also require additional setup for the app, /// especially in the app's `AndroidManifest.xml` file. Please see check the /// readme for further details. @@ -409,10 +383,8 @@ class FlutterLocalNotificationsPlugin { String? body, RepeatInterval repeatInterval, NotificationDetails notificationDetails, { + required AndroidScheduleMode androidScheduleMode, String? payload, - @Deprecated('Deprecated in favor of the androidScheduleMode parameter') - bool androidAllowWhileIdle = false, - AndroidScheduleMode? androidScheduleMode, }) async { if (kIsWeb) { return; @@ -423,8 +395,7 @@ class FlutterLocalNotificationsPlugin { ?.periodicallyShow(id, title, body, repeatInterval, notificationDetails: notificationDetails.android, payload: payload, - scheduleMode: _chooseScheduleMode( - androidScheduleMode, androidAllowWhileIdle)); + scheduleMode: androidScheduleMode); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>() @@ -490,13 +461,6 @@ class FlutterLocalNotificationsPlugin { } } - AndroidScheduleMode _chooseScheduleMode( - AndroidScheduleMode? scheduleMode, bool allowWhileIdle) => - scheduleMode ?? - (allowWhileIdle - ? AndroidScheduleMode.exactAllowWhileIdle - : AndroidScheduleMode.exact); - /// Returns a list of notifications pending to be delivered/shown. Future> pendingNotificationRequests() => FlutterLocalNotificationsPlatform.instance.pendingNotificationRequests(); diff --git a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart index 3889ee8c3..3c97c1c11 100644 --- a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart @@ -1954,6 +1954,7 @@ void main() { 'notification body', repeatInterval, const NotificationDetails(android: androidNotificationDetails), + androidScheduleMode: AndroidScheduleMode.exact, ); expect( diff --git a/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart b/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart index e18e70b1b..c788ce55b 100644 --- a/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart @@ -304,12 +304,12 @@ void main() { ); await flutterLocalNotificationsPlugin.periodicallyShow( - 1, - 'notification title', - 'notification body', - repeatInterval, - notificationDetails, - ); + 1, + 'notification title', + 'notification body', + repeatInterval, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exact); expect( log.last, diff --git a/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart b/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart index 6871604d3..9db86bc42 100644 --- a/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart @@ -217,6 +217,7 @@ void main() { 'notification body', repeatInterval, notificationDetails, + androidScheduleMode: AndroidScheduleMode.exact, ); expect( diff --git a/flutter_local_notifications_linux/CHANGELOG.md b/flutter_local_notifications_linux/CHANGELOG.md index 323da3a77..9574ac2e5 100644 --- a/flutter_local_notifications_linux/CHANGELOG.md +++ b/flutter_local_notifications_linux/CHANGELOG.md @@ -1,6 +1,6 @@ ## [vNext] -* Bumped minimum Flutter SDK requirement to 3.13 +* **Breaking change** Bumped minimum Flutter SDK requirement to 3.13 ## [4.0.1] diff --git a/flutter_local_notifications_platform_interface/CHANGELOG.md b/flutter_local_notifications_platform_interface/CHANGELOG.md index ca0af5997..847f58abe 100644 --- a/flutter_local_notifications_platform_interface/CHANGELOG.md +++ b/flutter_local_notifications_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## [vNext] -* Bumped minimum Flutter SDK requirement to 3.13 +* **Breaking change** Bumped minimum Flutter SDK requirement to 3.13 ## [7.2.0]