Skip to content

Commit

Permalink
[flutter_local_notifications] removed deprecated androidAllowWhileIdl…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
MaikuB authored Jul 14, 2024
1 parent 145ecc0 commit 49c487f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 51 deletions.
3 changes: 2 additions & 1 deletion flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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<
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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>()
Expand Down Expand Up @@ -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<List<PendingNotificationRequest>> pendingNotificationRequests() =>
FlutterLocalNotificationsPlatform.instance.pendingNotificationRequests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,7 @@ void main() {
'notification body',
repeatInterval,
const NotificationDetails(android: androidNotificationDetails),
androidScheduleMode: AndroidScheduleMode.exact,
);

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void main() {
'notification body',
repeatInterval,
notificationDetails,
androidScheduleMode: AndroidScheduleMode.exact,
);

expect(
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
Original file line number Diff line number Diff line change
@@ -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]

Expand Down

0 comments on commit 49c487f

Please sign in to comment.