Skip to content

Commit 7c3de83

Browse files
MaikuBrunnerrunner
authored
[flutter_local_notifications] added supported for banner and list presentation 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 <[email protected]> Co-authored-by: runner <[email protected]>
1 parent 2a56b88 commit 7c3de83

File tree

10 files changed

+389
-88
lines changed

10 files changed

+389
-88
lines changed

flutter_local_notifications/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# [vNext]
1+
# [15.0.0-dev.1]
22

33
* **Breaking change** removed deprecated `schedule`, `showDailyAtTime` and `showWeeklyAtDayAndTime` methods. Notifications that were scheduled prior to this release should still work
44
* **Breaking change** removed `Time` class
55
* [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`
6+
* **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.
7+
* Updated API documentation related to the iOS/macOS notification presentation options to include links to Apple's documentations to show what they correspond to
68

79
# [14.1.1]
810

flutter_local_notifications/example/lib/main.dart

Lines changed: 83 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,20 @@ class _HomePageState extends State<HomePage> {
872872
await _showNotificationWithTimeSensitiveInterruptionLevel();
873873
},
874874
),
875+
PaddedElevatedButton(
876+
buttonText: 'Show notification with banner but not in '
877+
'notification centre',
878+
onPressed: () async {
879+
await _showNotificationWithBannerNotInNotificationCentre();
880+
},
881+
),
882+
PaddedElevatedButton(
883+
buttonText:
884+
'Show notification in notification centre only',
885+
onPressed: () async {
886+
await _showNotificationInNotificationCentreOnly();
887+
},
888+
),
875889
],
876890
if (!kIsWeb && Platform.isLinux) ...<Widget>[
877891
const Text(
@@ -1328,7 +1342,9 @@ class _HomePageState extends State<HomePage> {
13281342
sound: RawResourceAndroidNotificationSound('slow_spring_board'),
13291343
);
13301344
const DarwinNotificationDetails darwinNotificationDetails =
1331-
DarwinNotificationDetails(sound: 'slow_spring_board.aiff');
1345+
DarwinNotificationDetails(
1346+
sound: 'slow_spring_board.aiff',
1347+
);
13321348
final LinuxNotificationDetails linuxPlatformChannelSpecifics =
13331349
LinuxNotificationDetails(
13341350
sound: AssetsLinuxSound('sound/slow_spring_board.mp3'),
@@ -1413,7 +1429,9 @@ class _HomePageState extends State<HomePage> {
14131429
playSound: false,
14141430
styleInformation: DefaultStyleInformation(true, true));
14151431
const DarwinNotificationDetails darwinNotificationDetails =
1416-
DarwinNotificationDetails(presentSound: false);
1432+
DarwinNotificationDetails(
1433+
presentSound: false,
1434+
);
14171435
const NotificationDetails notificationDetails = NotificationDetails(
14181436
android: androidNotificationDetails,
14191437
iOS: darwinNotificationDetails,
@@ -2073,7 +2091,9 @@ class _HomePageState extends State<HomePage> {
20732091

20742092
Future<void> _showNotificationWithSubtitle() async {
20752093
const DarwinNotificationDetails darwinNotificationDetails =
2076-
DarwinNotificationDetails(subtitle: 'the subtitle');
2094+
DarwinNotificationDetails(
2095+
subtitle: 'the subtitle',
2096+
);
20772097
const NotificationDetails notificationDetails = NotificationDetails(
20782098
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
20792099
await flutterLocalNotificationsPlugin.show(
@@ -2099,7 +2119,9 @@ class _HomePageState extends State<HomePage> {
20992119
String threadIdentifier,
21002120
) {
21012121
final DarwinNotificationDetails darwinNotificationDetails =
2102-
DarwinNotificationDetails(threadIdentifier: threadIdentifier);
2122+
DarwinNotificationDetails(
2123+
threadIdentifier: threadIdentifier,
2124+
);
21032125
return NotificationDetails(
21042126
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
21052127
}
@@ -2127,7 +2149,8 @@ class _HomePageState extends State<HomePage> {
21272149
Future<void> _showNotificationWithTimeSensitiveInterruptionLevel() async {
21282150
const DarwinNotificationDetails darwinNotificationDetails =
21292151
DarwinNotificationDetails(
2130-
interruptionLevel: InterruptionLevel.timeSensitive);
2152+
interruptionLevel: InterruptionLevel.timeSensitive,
2153+
);
21312154
const NotificationDetails notificationDetails = NotificationDetails(
21322155
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
21332156
await flutterLocalNotificationsPlugin.show(
@@ -2138,6 +2161,38 @@ class _HomePageState extends State<HomePage> {
21382161
payload: 'item x');
21392162
}
21402163

2164+
Future<void> _showNotificationWithBannerNotInNotificationCentre() async {
2165+
const DarwinNotificationDetails darwinNotificationDetails =
2166+
DarwinNotificationDetails(
2167+
presentBanner: true,
2168+
presentList: false,
2169+
);
2170+
const NotificationDetails notificationDetails = NotificationDetails(
2171+
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
2172+
await flutterLocalNotificationsPlugin.show(
2173+
id++,
2174+
'title of banner notification',
2175+
'body of banner notification',
2176+
notificationDetails,
2177+
payload: 'item x');
2178+
}
2179+
2180+
Future<void> _showNotificationInNotificationCentreOnly() async {
2181+
const DarwinNotificationDetails darwinNotificationDetails =
2182+
DarwinNotificationDetails(
2183+
presentBanner: false,
2184+
presentList: true,
2185+
);
2186+
const NotificationDetails notificationDetails = NotificationDetails(
2187+
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
2188+
await flutterLocalNotificationsPlugin.show(
2189+
id++,
2190+
'title of notification shown only in notification centre',
2191+
'body of notification shown only in notification centre',
2192+
notificationDetails,
2193+
payload: 'item x');
2194+
}
2195+
21412196
Future<void> _showNotificationWithoutTimestamp() async {
21422197
const AndroidNotificationDetails androidNotificationDetails =
21432198
AndroidNotificationDetails('your channel id', 'your channel name',
@@ -2212,12 +2267,14 @@ class _HomePageState extends State<HomePage> {
22122267
final String bigPicturePath = await _downloadAndSaveFile(
22132268
'https://dummyimage.com/600x200', 'bigPicture.jpg');
22142269
final DarwinNotificationDetails darwinNotificationDetails =
2215-
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
2216-
DarwinNotificationAttachment(
2217-
bigPicturePath,
2218-
hideThumbnail: hideThumbnail,
2219-
)
2220-
]);
2270+
DarwinNotificationDetails(
2271+
attachments: <DarwinNotificationAttachment>[
2272+
DarwinNotificationAttachment(
2273+
bigPicturePath,
2274+
hideThumbnail: hideThumbnail,
2275+
)
2276+
],
2277+
);
22212278
final NotificationDetails notificationDetails = NotificationDetails(
22222279
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
22232280
await flutterLocalNotificationsPlugin.show(
@@ -2231,19 +2288,21 @@ class _HomePageState extends State<HomePage> {
22312288
final String bigPicturePath = await _downloadAndSaveFile(
22322289
'https://dummyimage.com/600x200', 'bigPicture.jpg');
22332290
final DarwinNotificationDetails darwinNotificationDetails =
2234-
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
2235-
DarwinNotificationAttachment(
2236-
bigPicturePath,
2237-
thumbnailClippingRect:
2238-
// lower right quadrant of the attachment
2239-
const DarwinNotificationAttachmentThumbnailClippingRect(
2240-
x: 0.5,
2241-
y: 0.5,
2242-
height: 0.5,
2243-
width: 0.5,
2244-
),
2245-
)
2246-
]);
2291+
DarwinNotificationDetails(
2292+
attachments: <DarwinNotificationAttachment>[
2293+
DarwinNotificationAttachment(
2294+
bigPicturePath,
2295+
thumbnailClippingRect:
2296+
// lower right quadrant of the attachment
2297+
const DarwinNotificationAttachmentThumbnailClippingRect(
2298+
x: 0.5,
2299+
y: 0.5,
2300+
height: 0.5,
2301+
width: 0.5,
2302+
),
2303+
)
2304+
],
2305+
);
22472306
final NotificationDetails notificationDetails = NotificationDetails(
22482307
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
22492308
await flutterLocalNotificationsPlugin.show(

0 commit comments

Comments
 (0)