Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.lang.reflect.Type;


/** Created by michaelbui on 24/3/18. */
@Keep
public class ScheduledNotificationReceiver extends BroadcastReceiver {
Expand Down
6 changes: 3 additions & 3 deletions flutter_local_notifications/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ android {
signingConfig signingConfigs.debug
}
}

// Temporary workaround as per https://issuetracker.google.com/issues/158060799
lintOptions {
lint {
checkReleaseBuilds false
}

// Temporary workaround as per https://issuetracker.google.com/issues/158060799
}

flutter {
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Flutter plugin for displaying local notifications.
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '10.0'
end

Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,21 @@ class FlutterLocalNotificationsPlugin {
}
}

Future<void> zonedScheduleBatch(List<NotificationRequest> requests) async {
if (kIsWeb) {
return;
}
if (defaultTargetPlatform == TargetPlatform.android) {
await resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
.zonedScheduleBatch(requests);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()!
.zonedScheduleBatch(requests);
}
}

/// Periodically show a notification using the specified interval.
///
/// For example, specifying a hourly interval means the first time the
Expand Down Expand Up @@ -432,13 +447,7 @@ class FlutterLocalNotificationsPlugin {
?.showDailyAtTime(
id, title, body, notificationTime, notificationDetails.android,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.showDailyAtTime(
id, title, body, notificationTime, notificationDetails.iOS,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
} else {
throw UnimplementedError();
}
}
Expand Down Expand Up @@ -467,13 +476,7 @@ class FlutterLocalNotificationsPlugin {
?.showWeeklyAtDayAndTime(id, title, body, day, notificationTime,
notificationDetails.android,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.showWeeklyAtDayAndTime(
id, title, body, day, notificationTime, notificationDetails.iOS,
payload: payload);
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
} else {
throw UnimplementedError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class MethodChannelFlutterLocalNotificationsPlugin
@override
Future<void> cancelAll() => _channel.invokeMethod('cancelAll');

@override
Future<void> cancelAllPending() => _channel.invokeMethod('cancelAllPending');

@override
Future<NotificationAppLaunchDetails?>
getNotificationAppLaunchDetails() async {
Expand Down Expand Up @@ -187,6 +190,38 @@ class AndroidFlutterLocalNotificationsPlugin
}));
}

/// Schedules a batch of notifications to be shown at the specified date
/// and time relative to a specific time zone.
Future<void> zonedScheduleBatch(List<NotificationRequest> requests) async {
final List<Map<String, Object?>> serializedRequests =
<Map<String, Object?>>[];
for (final NotificationRequest request in requests) {
validateId(request.id);
validateDateIsInTheFuture(request.date, request.matchDateTimeComponents);
final Map<String, Object?> serializedPlatformSpecifics =
request.details.android?.toMap() ?? <String, Object>{};
serializedPlatformSpecifics['allowWhileIdle'] =
request.androidAllowWhileIdle;
serializedRequests.add(
<String, Object?>{
'id': request.id,
'title': request.title,
'body': request.body,
'platformSpecifics': serializedPlatformSpecifics,
'payload': request.payload ?? ''
}
..addAll(request.date.toMap())
..addAll(request.matchDateTimeComponents == null
? <String, Object>{}
: <String, Object>{
'matchDateTimeComponents':
request.matchDateTimeComponents!.index
}),
);
}
await _channel.invokeMethod('zonedScheduleBatch', serializedRequests);
}

/// Shows a notification on a daily interval at the specified time.
@Deprecated(
'Deprecated due to problems with time zones. Use zonedSchedule instead.')
Expand Down Expand Up @@ -605,54 +640,34 @@ class IOSFlutterLocalNotificationsPlugin
}));
}

/// Shows a notification on a daily interval at the specified time.
@Deprecated(
'Deprecated due to problems with time zones. Use zonedSchedule instead.')
Future<void> showDailyAtTime(
int id,
String? title,
String? body,
Time notificationTime,
DarwinNotificationDetails? notificationDetails, {
String? payload,
}) async {
validateId(id);
await _channel.invokeMethod('showDailyAtTime', <String, Object?>{
'id': id,
'title': title,
'body': body,
'calledAt': clock.now().millisecondsSinceEpoch,
'repeatInterval': RepeatInterval.daily.index,
'repeatTime': notificationTime.toMap(),
'platformSpecifics': notificationDetails?.toMap(),
'payload': payload ?? ''
});
}

/// Shows a notification on weekly interval at the specified day and time.
@Deprecated(
'Deprecated due to problems with time zones. Use zonedSchedule instead.')
Future<void> showWeeklyAtDayAndTime(
int id,
String? title,
String? body,
Day day,
Time notificationTime,
DarwinNotificationDetails? notificationDetails, {
String? payload,
}) async {
validateId(id);
await _channel.invokeMethod('showWeeklyAtDayAndTime', <String, Object?>{
'id': id,
'title': title,
'body': body,
'calledAt': clock.now().millisecondsSinceEpoch,
'repeatInterval': RepeatInterval.weekly.index,
'repeatTime': notificationTime.toMap(),
'day': day.value,
'platformSpecifics': notificationDetails?.toMap(),
'payload': payload ?? ''
});
/// Schedules a batch of notifications to be shown at the specified date
/// and time relative to a specific time zone.
Future<void> zonedScheduleBatch(List<NotificationRequest> requests) async {
final List<Map<String, Object?>> serializedRequests =
<Map<String, Object?>>[];
for (final NotificationRequest request in requests) {
validateId(request.id);
validateDateIsInTheFuture(request.date, request.matchDateTimeComponents);
final Map<String, Object?> serializedPlatformSpecifics =
request.details.iOS?.toMap() ?? <String, Object>{};
serializedRequests.add(
<String, Object?>{
'id': request.id,
'title': request.title,
'body': request.body,
'platformSpecifics': serializedPlatformSpecifics,
'payload': request.payload ?? '',
}
..addAll(request.date.toMap())
..addAll(request.matchDateTimeComponents == null
? <String, Object>{}
: <String, Object>{
'matchDateTimeComponents':
request.matchDateTimeComponents!.index
}),
);
}
await _channel.invokeMethod('zonedScheduleBatch', serializedRequests);
}

@override
Expand Down
26 changes: 26 additions & 0 deletions flutter_local_notifications/lib/src/types.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'package:timezone/timezone.dart';

import 'notification_details.dart';

/// The days of the week.
class Day {
/// Constructs an instance of [Day].
Expand Down Expand Up @@ -73,3 +77,25 @@ enum DateTimeComponents {
/// The date and time.
dateAndTime,
}

class NotificationRequest {
NotificationRequest({
required this.id,
required this.title,
required this.body,
required this.details,
required this.date,
required this.androidAllowWhileIdle,
this.payload,
this.matchDateTimeComponents,
});

final int id;
final String? title;
final String? body;
final String? payload;
final TZDateTime date;
final NotificationDetails details;
final DateTimeComponents? matchDateTimeComponents;
final bool androidAllowWhileIdle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface {
throw UnimplementedError('cancelAll() has not been implemented');
}

/// Cancels/removes all pending notifications. This applies to notifications that have been scheduled but not those that have already been presented.
Future<void> cancelAllPending() async {
throw UnimplementedError('cancelAllPending() has not been implemented');
}

/// Returns a list of notifications pending to be delivered/shown
Future<List<PendingNotificationRequest>> pendingNotificationRequests() {
throw UnimplementedError(
Expand Down