Skip to content

Commit

Permalink
[flutter_local_notifications] added supported for banner and list pre…
Browse files Browse the repository at this point in the history
…sentation options for iOS and macOS (#2016)

* added supported for banner and list presentation options on iOS

* support banner and list presentation options on macos along with configuring defaults

* Swift Format

* restore support of default presentation options on ios and keep in user defaults

* Clang Format

* removed print statements from macOS plugin code

* updated API docs, changelog and pubspec for release

---------

Co-authored-by: runner <runner@Mac-1685630501483.local>
Co-authored-by: runner <runner@Mac-1685631538518.local>
  • Loading branch information
3 people authored Jun 7, 2023
1 parent 2a56b88 commit 7c3de83
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 88 deletions.
4 changes: 3 additions & 1 deletion flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# [vNext]
# [15.0.0-dev.1]

* **Breaking change** removed deprecated `schedule`, `showDailyAtTime` and `showWeeklyAtDayAndTime` methods. Notifications that were scheduled prior to this release should still work
* **Breaking change** removed `Time` class
* [Android] updated tags used when writing error logs. For corrupt scheduled notifications and error is logged the tag is now `ScheduledNotifReceiver` instead of `ScheduledNotifReceiver`. When logging that exact alarm permissions have been revoked the the tag is now `FLTLocalNotifPlugin` instead of `notification`
* **Breaking change** [iOS][macOS] added supported for banner and list presentation options for iOS and macOS that is applicable for iOS 14.0 or newer and macOS 11 or newer. This is a breaking change as the values default to true and the alert presentation option is no longer applicable on these OS versions as Apple has deprecated it to be replaced by the banner and list presentations. Please ensure that if you target these OS versions that you configure the options appropriately for your application.
* Updated API documentation related to the iOS/macOS notification presentation options to include links to Apple's documentations to show what they correspond to

# [14.1.1]

Expand Down
107 changes: 83 additions & 24 deletions flutter_local_notifications/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,20 @@ class _HomePageState extends State<HomePage> {
await _showNotificationWithTimeSensitiveInterruptionLevel();
},
),
PaddedElevatedButton(
buttonText: 'Show notification with banner but not in '
'notification centre',
onPressed: () async {
await _showNotificationWithBannerNotInNotificationCentre();
},
),
PaddedElevatedButton(
buttonText:
'Show notification in notification centre only',
onPressed: () async {
await _showNotificationInNotificationCentreOnly();
},
),
],
if (!kIsWeb && Platform.isLinux) ...<Widget>[
const Text(
Expand Down Expand Up @@ -1328,7 +1342,9 @@ class _HomePageState extends State<HomePage> {
sound: RawResourceAndroidNotificationSound('slow_spring_board'),
);
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(sound: 'slow_spring_board.aiff');
DarwinNotificationDetails(
sound: 'slow_spring_board.aiff',
);
final LinuxNotificationDetails linuxPlatformChannelSpecifics =
LinuxNotificationDetails(
sound: AssetsLinuxSound('sound/slow_spring_board.mp3'),
Expand Down Expand Up @@ -1413,7 +1429,9 @@ class _HomePageState extends State<HomePage> {
playSound: false,
styleInformation: DefaultStyleInformation(true, true));
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(presentSound: false);
DarwinNotificationDetails(
presentSound: false,
);
const NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails,
iOS: darwinNotificationDetails,
Expand Down Expand Up @@ -2073,7 +2091,9 @@ class _HomePageState extends State<HomePage> {

Future<void> _showNotificationWithSubtitle() async {
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(subtitle: 'the subtitle');
DarwinNotificationDetails(
subtitle: 'the subtitle',
);
const NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
Expand All @@ -2099,7 +2119,9 @@ class _HomePageState extends State<HomePage> {
String threadIdentifier,
) {
final DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(threadIdentifier: threadIdentifier);
DarwinNotificationDetails(
threadIdentifier: threadIdentifier,
);
return NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
}
Expand Down Expand Up @@ -2127,7 +2149,8 @@ class _HomePageState extends State<HomePage> {
Future<void> _showNotificationWithTimeSensitiveInterruptionLevel() async {
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
interruptionLevel: InterruptionLevel.timeSensitive);
interruptionLevel: InterruptionLevel.timeSensitive,
);
const NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
Expand All @@ -2138,6 +2161,38 @@ class _HomePageState extends State<HomePage> {
payload: 'item x');
}

Future<void> _showNotificationWithBannerNotInNotificationCentre() async {
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
presentBanner: true,
presentList: false,
);
const NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
id++,
'title of banner notification',
'body of banner notification',
notificationDetails,
payload: 'item x');
}

Future<void> _showNotificationInNotificationCentreOnly() async {
const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
presentBanner: false,
presentList: true,
);
const NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
id++,
'title of notification shown only in notification centre',
'body of notification shown only in notification centre',
notificationDetails,
payload: 'item x');
}

Future<void> _showNotificationWithoutTimestamp() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('your channel id', 'your channel name',
Expand Down Expand Up @@ -2212,12 +2267,14 @@ class _HomePageState extends State<HomePage> {
final String bigPicturePath = await _downloadAndSaveFile(
'https://dummyimage.com/600x200', 'bigPicture.jpg');
final DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(
bigPicturePath,
hideThumbnail: hideThumbnail,
)
]);
DarwinNotificationDetails(
attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(
bigPicturePath,
hideThumbnail: hideThumbnail,
)
],
);
final NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
Expand All @@ -2231,19 +2288,21 @@ class _HomePageState extends State<HomePage> {
final String bigPicturePath = await _downloadAndSaveFile(
'https://dummyimage.com/600x200', 'bigPicture.jpg');
final DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(
bigPicturePath,
thumbnailClippingRect:
// lower right quadrant of the attachment
const DarwinNotificationAttachmentThumbnailClippingRect(
x: 0.5,
y: 0.5,
height: 0.5,
width: 0.5,
),
)
]);
DarwinNotificationDetails(
attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(
bigPicturePath,
thumbnailClippingRect:
// lower right quadrant of the attachment
const DarwinNotificationAttachmentThumbnailClippingRect(
x: 0.5,
y: 0.5,
height: 0.5,
width: 0.5,
),
)
],
);
final NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
Expand Down
Loading

0 comments on commit 7c3de83

Please sign in to comment.