diff --git a/flutter_local_notifications/example/lib/main.dart b/flutter_local_notifications/example/lib/main.dart index 479c6557034b72dc6a77941eb4b9e6940e5adc0d..6ab64205bf250caaa4b2e765d5f2df38cafb8ff6 100644 --- a/flutter_local_notifications/example/lib/main.dart +++ b/flutter_local_notifications/example/lib/main.dart @@ -435,14 +435,14 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Show plain notification that has no title with ' - 'payload${Platform.operatingSystem == 'ohos' ? "(api11 Unsupported)" : ""}', + 'payload${defaultTargetPlatform == TargetPlatform.ohos ? "(api11 or api12 Unsupported)" : ""}', onPressed: () async { await _showNotificationWithNoTitle(); }, ), PaddedElevatedButton( buttonText: 'Show plain notification that has no body with ' - 'payload${Platform.operatingSystem == 'ohos' ? "(api11 Unsupported)" : ""}', + 'payload${defaultTargetPlatform == TargetPlatform.ohos ? "(api11 or api12 Unsupported)" : ""}', onPressed: () async { await _showNotificationWithNoBody(); }, @@ -457,7 +457,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule notification to appear in 5 seconds ' - 'based on local time zone', + 'based on local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _zonedScheduleNotification(); }, @@ -465,13 +465,14 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule notification to appear in 5 seconds ' - 'based on local time zone using alarm clock', + 'based on local time zone using alarm clock${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _zonedScheduleAlarmClockNotification(); }, ), PaddedElevatedButton( - buttonText: 'Repeat notification every minute', + buttonText: + 'Repeat notification every minute${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _repeatNotification(); }, @@ -479,7 +480,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule daily 10:00:00 am notification in your ' - 'local time zone', + 'local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _scheduleDailyTenAMNotification(); }, @@ -487,7 +488,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule daily 10:00:00 am notification in your ' - "local time zone using last year's date", + "local time zone using last year's date${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}", onPressed: () async { await _scheduleDailyTenAMLastYearNotification(); }, @@ -495,7 +496,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule weekly 10:00:00 am notification in your ' - 'local time zone', + 'local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _scheduleWeeklyTenAMNotification(); }, @@ -503,7 +504,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule weekly Monday 10:00:00 am notification ' - 'in your local time zone', + 'in your local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _scheduleWeeklyMondayTenAMNotification(); }, @@ -524,7 +525,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule monthly Monday 10:00:00 am notification in ' - 'your local time zone', + 'your local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _scheduleMonthlyMondayTenAMNotification(); }, @@ -532,7 +533,7 @@ class _HomePageState extends State { PaddedElevatedButton( buttonText: 'Schedule yearly Monday 10:00:00 am notification in ' - 'your local time zone', + 'your local time zone${defaultTargetPlatform == TargetPlatform.ohos ? "(Not a system app, not supported)" : ""}', onPressed: () async { await _scheduleYearlyMondayTenAMNotification(); }, @@ -590,7 +591,8 @@ class _HomePageState extends State { ), if (!Platform.isLinux) PaddedElevatedButton( - buttonText: 'Show notification with text choice${Platform.operatingSystem == 'ohos' ? "(api11 Unsupported)" : ""}', + buttonText: + 'Show notification with text choice${defaultTargetPlatform == TargetPlatform.ohos ? "(api11 or api12 Unsupported)" : ""}', onPressed: () async { await _showNotificationWithTextChoice(); }, @@ -856,7 +858,7 @@ class _HomePageState extends State { Text('notifications enabled: $_notificationsEnabled'), PaddedElevatedButton( buttonText: - 'Check if notifications are enabled for this app', + 'Check if notifications are enabled for this app', onPressed: _areNotifcationsEnabled, ), PaddedElevatedButton( @@ -865,7 +867,7 @@ class _HomePageState extends State { ), PaddedElevatedButton( buttonText: - 'Show plain notification with payload and update ' + 'Show plain notification with payload and update ' 'channel description', onPressed: () async { await _showNotificationUpdateChannelDescription(); @@ -880,29 +882,29 @@ class _HomePageState extends State { ), PaddedElevatedButton( buttonText: - 'Show notification with custom vibration pattern, ' - 'red LED and red icon', + 'Show notification with custom vibration pattern, ' + 'red LED and red icon${defaultTargetPlatform == TargetPlatform.ohos ? "(color Unsupported)" : ""}', onPressed: () async { await _showNotificationCustomVibrationIconLed(); }, ), PaddedElevatedButton( buttonText: - 'Show notification that times out after 3 seconds', + 'Show notification that times out after 3 seconds', onPressed: () async { await _showTimeoutNotification(); }, ), PaddedElevatedButton( buttonText: - 'Show big picture notification using local images', + 'Show big picture notification using local images', onPressed: () async { await _showBigPictureNotification(); }, ), PaddedElevatedButton( buttonText: - 'Show big picture notification using base64 String ' + 'Show big picture notification using base64 String ' 'for images', onPressed: () async { await _showBigPictureNotificationBase64(); @@ -910,7 +912,7 @@ class _HomePageState extends State { ), PaddedElevatedButton( buttonText: - 'Show big picture notification using URLs for ' + 'Show big picture notification using URLs for ' 'Images', onPressed: () async { await _showBigPictureNotificationURL(); @@ -929,13 +931,15 @@ class _HomePageState extends State { }, ), PaddedElevatedButton( - buttonText: 'Show messaging notification', + buttonText: + 'Show messaging notification${defaultTargetPlatform == TargetPlatform.ohos ? "(Unsupported)" : ""}', onPressed: () async { await _showMessagingNotification(); }, ), PaddedElevatedButton( - buttonText: 'Show LiveView notification', + buttonText: + 'Show LiveView notification${defaultTargetPlatform == TargetPlatform.ohos ? "(api11 or api12 Unsupported)" : ""}', onPressed: () async { await _showLiveViewNotification(); }, @@ -959,21 +963,21 @@ class _HomePageState extends State { }, ), PaddedElevatedButton( - buttonText: 'Show ongoing notification', + buttonText: 'Show ongoing notification${defaultTargetPlatform == TargetPlatform.ohos ? "(ongoing Unsupported)" : ""}', onPressed: () async { await _showOngoingNotification(); }, ), PaddedElevatedButton( buttonText: - 'Show notification with no badge, alert only once', + 'Show notification with no badge, alert only once', onPressed: () async { await _showNotificationWithNoBadge(); }, ), PaddedElevatedButton( buttonText: - 'Show progress notification - updates every second', + 'Show progress notification - updates every second', onPressed: () async { await _showProgressNotification(); }, @@ -1010,7 +1014,7 @@ class _HomePageState extends State { ), PaddedElevatedButton( buttonText: - 'Show notification with number if the launcher ' + 'Show notification with number if the launcher ' 'supports', onPressed: () async { await _showNotificationWithNumber(); @@ -1023,7 +1027,7 @@ class _HomePageState extends State { }, ), PaddedElevatedButton( - buttonText: 'Show no float icon notification', + buttonText: 'Show no float icon notification${defaultTargetPlatform == TargetPlatform.ohos ? "(no float icon Unsupported)" : ""}', onPressed: () async { await _showNotificationIsFloatingIcon(); }, @@ -1446,8 +1450,7 @@ class _HomePageState extends State { 'text_id_1', 'Enter Text', inputs: [ - OhosNotificationActionInput( - ), + OhosNotificationActionInput(), ], ), ], @@ -1459,11 +1462,10 @@ class _HomePageState extends State { ); const NotificationDetails notificationDetails = NotificationDetails( - android: androidNotificationDetails, - iOS: darwinNotificationDetails, - macOS: darwinNotificationDetails, - ohos: ohosNotificationDetails - ); + android: androidNotificationDetails, + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show(id++, 'Text Input Notification', 'Expand to see input action', notificationDetails, @@ -1579,13 +1581,11 @@ class _HomePageState extends State { priority: Priority.high, ticker: 'ticker'); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high); const NotificationDetails notificationDetails = NotificationDetails( - android: androidNotificationDetails, - ohos: ohosNotificationDetails - ); + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', null, notificationDetails, payload: 'item x'); @@ -1599,13 +1599,11 @@ class _HomePageState extends State { priority: Priority.high, ticker: 'ticker'); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high); const NotificationDetails notificationDetails = NotificationDetails( - android: androidNotificationDetails, - ohos: ohosNotificationDetails - ); + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin .show(id++, null, 'plain body', notificationDetails, payload: 'item x'); } @@ -1635,7 +1633,7 @@ class _HomePageState extends State { sound: AssetsLinuxSound('sound/slow_spring_board.mp3'), ); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails( + OhosNotificationDetails( OhosNotificationSlotType.CONTENT_INFORMATION, slotDesc: 'your other channel description', importance: OhosImportance.high, @@ -1661,6 +1659,7 @@ class _HomePageState extends State { vibrationPattern[1] = 1000; vibrationPattern[2] = 5000; vibrationPattern[3] = 2000; + final List vibrationPatternOhos = [0, 1000, 5000, 2000]; final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( @@ -1675,18 +1674,18 @@ class _HomePageState extends State { ledOnMs: 1000, ledOffMs: 500); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails( - OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'other custom channel description', - icon: 'secondary_icon', - largeIcon: const DrawableResourceOhosPixelMap('sample_large_icon'), - vibrationPattern: vibrationPattern, - enableLights: true, - color: const Color.fromARGB(255, 255, 0, 0), - ledColor: const Color.fromARGB(255, 255, 0, 0)); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'other custom channel description', + icon: 'secondary_icon', + largeIcon: const DrawableResourceOhosPixelMap('sample_large_icon'), + vibrationPattern: vibrationPatternOhos, + enableLights: true, + colorized: true, + color: const Color.fromARGB(255, 255, 0, 0), + ledColor: const Color.fromARGB(255, 255, 0, 0)); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'title of notification with custom vibration pattern, LED and icon', @@ -1704,8 +1703,9 @@ class _HomePageState extends State { android: AndroidNotificationDetails( 'your channel id', 'your channel name', channelDescription: 'your channel description'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description')), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime); @@ -1721,8 +1721,9 @@ class _HomePageState extends State { android: AndroidNotificationDetails( 'alarm_clock_channel', 'Alarm Clock Channel', channelDescription: 'Alarm Clock Notification'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'Alarm Clock Notification')), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'Alarm Clock Notification')), androidScheduleMode: AndroidScheduleMode.alarmClock, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime); @@ -1735,10 +1736,10 @@ class _HomePageState extends State { playSound: false, styleInformation: DefaultStyleInformation(true, true)); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'silent channel description', - playSound: false, - styleInformation: OhosDefaultStyleInformation(true, true)); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'silent channel description', + playSound: false, + styleInformation: OhosDefaultStyleInformation(true, true)); const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( presentSound: false, @@ -1747,7 +1748,7 @@ class _HomePageState extends State { android: androidNotificationDetails, iOS: darwinNotificationDetails, macOS: darwinNotificationDetails, - ohos: ohosNotificationDetails); + ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'silent title', 'silent body', notificationDetails); } @@ -1761,10 +1762,10 @@ class _HomePageState extends State { ticker: 'ticker', silent: true); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - silent: true); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + silent: true); const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( presentSound: false, @@ -1772,7 +1773,8 @@ class _HomePageState extends State { const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, iOS: darwinNotificationDetails, - macOS: darwinNotificationDetails, ohos: ohosNotificationDetails); + macOS: darwinNotificationDetails, + ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'silent title', 'silent body', notificationDetails); } @@ -1802,12 +1804,12 @@ class _HomePageState extends State { timeoutAfter: 3000, styleInformation: DefaultStyleInformation(true, true)); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'silent channel description', - timeoutAfter: 3000, - styleInformation: OhosDefaultStyleInformation(true, true)); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'silent channel description', + timeoutAfter: 3000, + styleInformation: OhosDefaultStyleInformation(true, true)); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show(id++, 'timeout notification', 'Times out after 3 seconds', notificationDetails); } @@ -1822,8 +1824,10 @@ class _HomePageState extends State { priority: Priority.high, ticker: 'ticker', additionalFlags: Int32List.fromList([insistentFlag])); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: const OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION)); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ohos: const OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION)); await flutterLocalNotificationsPlugin.show( id++, 'insistent title', 'insistent body', notificationDetails, payload: 'item x'); @@ -1856,19 +1860,18 @@ class _HomePageState extends State { channelDescription: 'big text channel description', styleInformation: bigPictureStyleInformation); final OhosBigPictureStyleInformation bigPictureStyleInformationOhos = - OhosBigPictureStyleInformation(FilePathOhosPixelMap(bigPicturePath), - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + OhosBigPictureStyleInformation(FilePathOhosPixelMap(bigPicturePath), + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - largeIcon: FilePathOhosPixelMap(largeIconPath), - slotDesc: 'big text channel description', - styleInformation: bigPictureStyleInformationOhos); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, - ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + largeIcon: FilePathOhosPixelMap(largeIconPath), + slotDesc: 'big text channel description', + styleInformation: bigPictureStyleInformationOhos); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'big picture title', 'big picture body', notificationDetails); } @@ -1900,20 +1903,20 @@ class _HomePageState extends State { channelDescription: 'big text channel description', styleInformation: bigPictureStyleInformation); final OhosBigPictureStyleInformation bigPictureStyleInformationOhos = - OhosBigPictureStyleInformation( - ByteArrayOhosPixelMap.fromBase64String( - bigPicture), //Base64AndroidBitmap(bigPicture), - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + OhosBigPictureStyleInformation( + ByteArrayOhosPixelMap.fromBase64String( + bigPicture), //Base64AndroidBitmap(bigPicture), + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - largeIcon: ByteArrayOhosPixelMap.fromBase64String(largeIcon), - slotDesc: 'big text channel description', - styleInformation: bigPictureStyleInformationOhos); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + largeIcon: ByteArrayOhosPixelMap.fromBase64String(largeIcon), + slotDesc: 'big text channel description', + styleInformation: bigPictureStyleInformationOhos); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'big picture title', 'big picture body', notificationDetails); } @@ -1924,10 +1927,14 @@ class _HomePageState extends State { } Future _showBigPictureNotificationURL() async { - final Uint8List largeIconArray = await _getByteArrayFromUrl('https://dummyimage.com/48x48'); - final Uint8List bigPictureArray = await _getByteArrayFromUrl('https://dummyimage.com/400x800'); - final ByteArrayAndroidBitmap largeIcon = ByteArrayAndroidBitmap(largeIconArray); - final ByteArrayAndroidBitmap bigPicture = ByteArrayAndroidBitmap(bigPictureArray); + final Uint8List largeIconArray = + await _getByteArrayFromUrl('https://dummyimage.com/48x48'); + final Uint8List bigPictureArray = + await _getByteArrayFromUrl('https://dummyimage.com/400x800'); + final ByteArrayAndroidBitmap largeIcon = + ByteArrayAndroidBitmap(largeIconArray); + final ByteArrayAndroidBitmap bigPicture = + ByteArrayAndroidBitmap(bigPictureArray); final BigPictureStyleInformation bigPictureStyleInformation = BigPictureStyleInformation(bigPicture, @@ -1941,21 +1948,23 @@ class _HomePageState extends State { 'big text channel id', 'big text channel name', channelDescription: 'big text channel description', styleInformation: bigPictureStyleInformation); - final ByteArrayOhosPixelMap largeIconOhos = ByteArrayOhosPixelMap(largeIconArray); - final ByteArrayOhosPixelMap bigPictureOhos = ByteArrayOhosPixelMap(bigPictureArray); + final ByteArrayOhosPixelMap largeIconOhos = + ByteArrayOhosPixelMap(largeIconArray); + final ByteArrayOhosPixelMap bigPictureOhos = + ByteArrayOhosPixelMap(bigPictureArray); final OhosBigPictureStyleInformation bigPictureStyleInformationOhos = - OhosBigPictureStyleInformation(bigPictureOhos, - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + OhosBigPictureStyleInformation(bigPictureOhos, + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - largeIcon: largeIconOhos, - slotDesc: 'big text channel description', - styleInformation: bigPictureStyleInformationOhos); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + largeIcon: largeIconOhos, + slotDesc: 'big text channel description', + styleInformation: bigPictureStyleInformationOhos); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'big picture title', 'big picture body', notificationDetails); } @@ -2017,7 +2026,7 @@ class _HomePageState extends State { channelDescription: 'big text channel description', styleInformation: bigTextStyleInformation); const OhosBigTextStyleInformation bigTextStyleInformationOhos = - OhosBigTextStyleInformation( + OhosBigTextStyleInformation( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', htmlFormatBigText: true, contentTitle: 'overridden big content title', @@ -2026,12 +2035,11 @@ class _HomePageState extends State { htmlFormatSummaryText: true, ); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'big text channel description', - styleInformation: bigTextStyleInformationOhos); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, - ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'big text channel description', + styleInformation: bigTextStyleInformationOhos); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'big text title', 'silent body', notificationDetails); } @@ -2049,19 +2057,19 @@ class _HomePageState extends State { AndroidNotificationDetails('inbox channel id', 'inboxchannel name', channelDescription: 'inbox channel description', styleInformation: inboxStyleInformation); - final OhosInboxStyleInformation inboxStyleInformationOhos = OhosInboxStyleInformation( - lines, - htmlFormatLines: true, - contentTitle: 'overridden inbox context title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + final OhosInboxStyleInformation inboxStyleInformationOhos = + OhosInboxStyleInformation(lines, + htmlFormatLines: true, + contentTitle: 'overridden inbox context title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'inbox channel description', - styleInformation: inboxStyleInformationOhos); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'inbox channel description', + styleInformation: inboxStyleInformationOhos); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'inbox title', 'inbox body', notificationDetails); } @@ -2158,12 +2166,14 @@ class _HomePageState extends State { priority: Priority.high, groupKey: groupKey); const OhosNotificationDetails firstNotificationOhosSpecifics = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: groupChannelDescription, - importance: OhosImportance.high, - groupKey: groupKey); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: groupChannelDescription, + importance: OhosImportance.high, + groupKey: groupKey); const NotificationDetails firstNotificationPlatformSpecifics = - NotificationDetails(android: firstNotificationAndroidSpecifics, ohos: firstNotificationOhosSpecifics); + NotificationDetails( + android: firstNotificationAndroidSpecifics, + ohos: firstNotificationOhosSpecifics); await flutterLocalNotificationsPlugin.show(id++, 'Alex Faarborg', 'You will not believe...', firstNotificationPlatformSpecifics); const AndroidNotificationDetails secondNotificationAndroidSpecifics = @@ -2173,12 +2183,14 @@ class _HomePageState extends State { priority: Priority.high, groupKey: groupKey); const OhosNotificationDetails secondNotificationOhosSpecifics = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: groupChannelDescription, - importance: OhosImportance.high, - groupKey: groupKey); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: groupChannelDescription, + importance: OhosImportance.high, + groupKey: groupKey); const NotificationDetails secondNotificationPlatformSpecifics = - NotificationDetails(android: secondNotificationAndroidSpecifics, ohos: secondNotificationOhosSpecifics); + NotificationDetails( + android: secondNotificationAndroidSpecifics, + ohos: secondNotificationOhosSpecifics); await flutterLocalNotificationsPlugin.show( id++, 'Jeff Chang', @@ -2204,17 +2216,16 @@ class _HomePageState extends State { styleInformation: inboxStyleInformation, groupKey: groupKey, setAsGroupSummary: true); - const OhosInboxStyleInformation inboxStyleInformationOhos = OhosInboxStyleInformation( - lines, - contentTitle: '2 messages', - summaryText: 'janedoe@example.com'); + const OhosInboxStyleInformation inboxStyleInformationOhos = + OhosInboxStyleInformation(lines, + contentTitle: '2 messages', summaryText: 'janedoe@example.com'); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: groupChannelDescription, - styleInformation: inboxStyleInformationOhos, - groupKey: groupKey); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: groupChannelDescription, + styleInformation: inboxStyleInformationOhos, + groupKey: groupKey); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'Attention', 'Two messages', notificationDetails); } @@ -2227,15 +2238,14 @@ class _HomePageState extends State { priority: Priority.high, tag: 'tag'); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - tag: 'tag'); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + tag: 'tag'); const NotificationDetails notificationDetails = NotificationDetails( - android: androidNotificationDetails, ohos: ohosNotificationDetails - ); - await flutterLocalNotificationsPlugin.show( - id++, 'first notification', 'first notification body', notificationDetails); + android: androidNotificationDetails, ohos: ohosNotificationDetails); + await flutterLocalNotificationsPlugin.show(id++, 'first notification', + 'first notification body', notificationDetails); } Future _checkPendingNotificationRequests() async { @@ -2272,13 +2282,13 @@ class _HomePageState extends State { ongoing: true, autoCancel: false); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - ongoing: true, - autoCancel: false); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + ongoing: true, + autoCancel: false); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'ongoing notification title', @@ -2292,10 +2302,10 @@ class _HomePageState extends State { 'repeating channel id', 'repeating channel name', channelDescription: 'repeating description'); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION - , slotDesc: 'repeating description'); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'repeating description'); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.periodicallyShow( id++, 'repeating title', @@ -2313,12 +2323,12 @@ class _HomePageState extends State { 'daily scheduled notification body', _nextInstanceOfTenAM(), const NotificationDetails( - android: AndroidNotificationDetails('daily notification channel id', - 'daily notification channel name', - channelDescription: 'daily notification description'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION - , slotDesc: 'daily notification description') - ), + android: AndroidNotificationDetails('daily notification channel id', + 'daily notification channel name', + channelDescription: 'daily notification description'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'daily notification description')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2333,12 +2343,12 @@ class _HomePageState extends State { 'daily scheduled notification body', _nextInstanceOfTenAMLastYear(), const NotificationDetails( - android: AndroidNotificationDetails('daily notification channel id', - 'daily notification channel name', - channelDescription: 'daily notification description'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'daily notification description') - ), + android: AndroidNotificationDetails('daily notification channel id', + 'daily notification channel name', + channelDescription: 'daily notification description'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'daily notification description')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2352,12 +2362,13 @@ class _HomePageState extends State { 'weekly scheduled notification body', _nextInstanceOfTenAM(), const NotificationDetails( - android: AndroidNotificationDetails('weekly notification channel id', - 'weekly notification channel name', - channelDescription: 'weekly notificationdescription'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'weekly notificationdescription') - ), + android: AndroidNotificationDetails( + 'weekly notification channel id', + 'weekly notification channel name', + channelDescription: 'weekly notificationdescription'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'weekly notificationdescription')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2371,12 +2382,13 @@ class _HomePageState extends State { 'weekly scheduled notification body', _nextInstanceOfMondayTenAM(), const NotificationDetails( - android: AndroidNotificationDetails('weekly notification channel id', - 'weekly notification channel name', - channelDescription: 'weekly notificationdescription'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'weekly notificationdescription') - ), + android: AndroidNotificationDetails( + 'weekly notification channel id', + 'weekly notification channel name', + channelDescription: 'weekly notificationdescription'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'weekly notificationdescription')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2390,12 +2402,13 @@ class _HomePageState extends State { 'monthly scheduled notification body', _nextInstanceOfMondayTenAM(), const NotificationDetails( - android: AndroidNotificationDetails('monthly notification channel id', - 'monthly notification channel name', - channelDescription: 'monthly notificationdescription'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'monthly notificationdescription') - ), + android: AndroidNotificationDetails( + 'monthly notification channel id', + 'monthly notification channel name', + channelDescription: 'monthly notificationdescription'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'monthly notificationdescription')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2409,12 +2422,13 @@ class _HomePageState extends State { 'yearly scheduled notification body', _nextInstanceOfMondayTenAM(), const NotificationDetails( - android: AndroidNotificationDetails('yearly notification channel id', - 'yearly notification channel name', - channelDescription: 'yearly notification description'), - ohos: OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'yearly notification description') - ), + android: AndroidNotificationDetails( + 'yearly notification channel id', + 'yearly notification channel name', + channelDescription: 'yearly notification description'), + ohos: OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'yearly notification description')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, @@ -2453,13 +2467,13 @@ class _HomePageState extends State { priority: Priority.high, onlyAlertOnce: true); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'no badge description', - slotShowBadge: false, - importance: OhosImportance.high, - onlyAlertOnce: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'no badge description', + slotShowBadge: false, + importance: OhosImportance.high, + onlyAlertOnce: true); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'no badge title', 'no badge body', notificationDetails, payload: 'item x'); @@ -2482,16 +2496,17 @@ class _HomePageState extends State { maxProgress: maxProgress, progress: i); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'progress channel description', - slotShowBadge: false, - importance: OhosImportance.high, - onlyAlertOnce: true, - showProgress: true, - maxProgress: maxProgress, - progress: i); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'progress channel description', + slotShowBadge: false, + importance: OhosImportance.high, + onlyAlertOnce: true, + showProgress: true, + maxProgress: maxProgress, + progress: i); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( progressId, 'progress notification title', @@ -2514,16 +2529,15 @@ class _HomePageState extends State { showProgress: true, indeterminate: true); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails( - OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'indeterminate progress channel description', - slotShowBadge: false, - importance: OhosImportance.high, - onlyAlertOnce: true, - showProgress: true, - indeterminate: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'indeterminate progress channel description', + slotShowBadge: false, + importance: OhosImportance.high, + onlyAlertOnce: true, + showProgress: true, + indeterminate: true); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'indeterminate progress notification title', @@ -2540,12 +2554,12 @@ class _HomePageState extends State { priority: Priority.high, channelAction: AndroidNotificationChannelAction.update); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your updated channel description', - importance: OhosImportance.high, - slotAction: OhosNotificationSlotAction.update); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your updated channel description', + importance: OhosImportance.high, + slotAction: OhosNotificationSlotAction.update); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'updated notification channel', @@ -2563,12 +2577,12 @@ class _HomePageState extends State { ticker: 'ticker', visibility: NotificationVisibility.public); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - lockscreenVisibility: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + lockscreenVisibility: true); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'public notification title', @@ -2689,12 +2703,12 @@ class _HomePageState extends State { priority: Priority.high, showWhen: false); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - showWhen: false); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + showWhen: false); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', 'plain body', notificationDetails, payload: 'item x'); @@ -2711,13 +2725,14 @@ class _HomePageState extends State { when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, ); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, slotDesc: 'your channel description', importance: OhosImportance.high, when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, ); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', 'plain body', notificationDetails, payload: 'item x'); @@ -2735,14 +2750,15 @@ class _HomePageState extends State { subText: 'custom subtext', ); const OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, slotDesc: 'your channel description', importance: OhosImportance.high, showWhen: false, subText: 'custom subtext', ); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', 'plain body', notificationDetails, payload: 'item x'); @@ -2761,15 +2777,16 @@ class _HomePageState extends State { chronometerCountDown: true, ); final OhosNotificationDetails ohosNotificationDetails = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + OhosNotificationDetails( + OhosNotificationSlotType.CONTENT_INFORMATION, slotDesc: 'your channel description', importance: OhosImportance.high, when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, usesChronometer: true, chronometerCountDown: true, ); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails, ohos: ohosNotificationDetails); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ohos: ohosNotificationDetails); await flutterLocalNotificationsPlugin.show( id++, 'plain title', 'plain body', notificationDetails, payload: 'item x'); @@ -2968,43 +2985,43 @@ class _HomePageState extends State { } Future _addNotificationSlot() async { - const OhosNotificationSlot ohosNotificationSlot = - OhosNotificationSlot( + const OhosNotificationSlot ohosNotificationSlot = OhosNotificationSlot( OhosNotificationSlotType.CONTENT_INFORMATION, description: 'your slot description', ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - OhosFlutterLocalNotificationsPlugin>() + OhosFlutterLocalNotificationsPlugin>() ?.addNotificationSlot(ohosNotificationSlot); await showDialog( context: context, builder: (BuildContext context) => AlertDialog( - content: - Text('Slot with name ${ohosNotificationSlot.slotType.name} ' - 'created'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + content: + Text('Slot with name ${ohosNotificationSlot.slotType.name} ' + 'created'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + )); } Future _deleteNotificationSlot() async { - const OhosNotificationSlotType slotType = OhosNotificationSlotType.CONTENT_INFORMATION; + const OhosNotificationSlotType slotType = + OhosNotificationSlotType.CONTENT_INFORMATION; await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - OhosFlutterLocalNotificationsPlugin>() + OhosFlutterLocalNotificationsPlugin>() ?.deleteNotificationSlot(slotType); await showDialog( context: context, builder: (BuildContext context) => AlertDialog( - content: Text('Channel with id ${slotType.name} deleted'), + content: Text('Channel with id ${slotType.name} deleted'), actions: [ TextButton( onPressed: () { @@ -3019,7 +3036,7 @@ class _HomePageState extends State { Future _getNotificationSlots() async { final Widget notificationChannelsDialogContent = - await _getNotificationSlotsDialogContent(); + await _getNotificationSlotsDialogContent(); await showDialog( context: context, builder: (BuildContext context) => AlertDialog( @@ -3039,10 +3056,10 @@ class _HomePageState extends State { Future _getNotificationSlotsDialogContent() async { try { final List? slots = - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - OhosFlutterLocalNotificationsPlugin>()! - .getNotificationSlots(); + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + OhosFlutterLocalNotificationsPlugin>()! + .getNotificationSlots(); return Container( width: double.maxFinite, @@ -3079,8 +3096,8 @@ class _HomePageState extends State { } on PlatformException catch (error) { return Text( 'Error calling "getNotificationSlots"\n' - 'code: ${error.code}\n' - 'message: ${error.message}', + 'code: ${error.code}\n' + 'message: ${error.message}', ); } } @@ -3090,12 +3107,12 @@ class _HomePageState extends State { if (Platform.isAndroid) { areEnabled = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin>() ?.areNotificationsEnabled(); } else if (Platform.operatingSystem == 'ohos') { areEnabled = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - OhosFlutterLocalNotificationsPlugin>() + OhosFlutterLocalNotificationsPlugin>() ?.areNotificationsEnabled(); } setState(() { @@ -3453,12 +3470,13 @@ class _HomePageState extends State { priority: Priority.high, number: 1); const OhosNotificationDetails ohosPlatformChannelSpecifics = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - slotDesc: 'your channel description', - importance: OhosImportance.high, - badgeNumber: 1); - const NotificationDetails platformChannelSpecifics = - NotificationDetails(android: androidPlatformChannelSpecifics, ohos: ohosPlatformChannelSpecifics); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + slotDesc: 'your channel description', + importance: OhosImportance.high, + badgeNumber: 1); + const NotificationDetails platformChannelSpecifics = NotificationDetails( + android: androidPlatformChannelSpecifics, + ohos: ohosPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.show( 0, 'icon badge title', 'icon badge body', platformChannelSpecifics, payload: 'item x'); @@ -3466,10 +3484,10 @@ class _HomePageState extends State { Future _showNotificationBypassDnd() async { const OhosNotificationDetails ohosPlatformChannelSpecifics = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - bypassDnd: true); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + bypassDnd: true); const NotificationDetails platformChannelSpecifics = - NotificationDetails(ohos: ohosPlatformChannelSpecifics); + NotificationDetails(ohos: ohosPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.show( 0, 'bypassDnd title', 'bypassDnd body', platformChannelSpecifics, payload: 'item x'); @@ -3477,12 +3495,12 @@ class _HomePageState extends State { Future _showNotificationIsFloatingIcon() async { const OhosNotificationDetails ohosPlatformChannelSpecifics = - OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, - isFloatingIcon: false); + OhosNotificationDetails(OhosNotificationSlotType.CONTENT_INFORMATION, + isFloatingIcon: false); const NotificationDetails platformChannelSpecifics = - NotificationDetails(ohos: ohosPlatformChannelSpecifics); - await flutterLocalNotificationsPlugin.show( - 0, 'no float icon title', 'no float icon body', platformChannelSpecifics, + NotificationDetails(ohos: ohosPlatformChannelSpecifics); + await flutterLocalNotificationsPlugin.show(0, 'no float icon title', + 'no float icon body', platformChannelSpecifics, payload: 'item x'); } diff --git a/flutter_local_notifications/lib/src/platform_specifics/ohos/enums.dart b/flutter_local_notifications/lib/src/platform_specifics/ohos/enums.dart index 4f416d2b65f4489611900a1bb248b58b74bf88d0..884f191a29ef8f213f17a3d26f4f49371261c238 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/ohos/enums.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/ohos/enums.dart @@ -66,7 +66,8 @@ enum OhosNotificationSlotType { SERVICE_INFORMATION(2), CONTENT_INFORMATION(3), LIVE_VIEW(4), - CUSTOMER_SERVICE(5); + CUSTOMER_SERVICE(5), + OTHER_TYPES(0xFFFF); const OhosNotificationSlotType(this.value); final int value; diff --git a/flutter_local_notifications/lib/src/platform_specifics/ohos/notification_details.dart b/flutter_local_notifications/lib/src/platform_specifics/ohos/notification_details.dart index 96b2861383f3ebf6770a9d61c6f1c11dc27280dc..6c26adb95702a832b7b8b765f093936cf6dcbddd 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/ohos/notification_details.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/ohos/notification_details.dart @@ -13,6 +13,7 @@ * limitations under the License. */ +import 'dart:ffi'; import 'dart:typed_data'; import 'dart:ui'; @@ -92,7 +93,9 @@ class OhosNotificationDetails { final bool enableLights; - final Int64List? vibrationPattern; + // final Int64List? vibrationPattern; + + final List? vibrationPattern; final OhosStyleInformation? styleInformation; diff --git a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/LocalNotificationsConstants.ets b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/LocalNotificationsConstants.ets index 1c2d9132c8fd5f8bdf5e3ab9caf8a0bf56eb7a7b..aba66449eb17edc8e405df80bde010396fcdaebf 100644 --- a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/LocalNotificationsConstants.ets +++ b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/LocalNotificationsConstants.ets @@ -107,6 +107,7 @@ export class LocalNotificationsConstants { static VIBRATION_PATTERN = "vibrationPattern"; static IS_FLOAT_ICON = "isFloatingIcon"; + static COLORIZED = "colorized"; static ENABLE_LIGHTS = "enableLights"; static LED_COLOR_ALPHA = "ledColorAlpha"; static LED_COLOR_RED = "ledColorRed"; diff --git a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/MethodCallHandlerImpl.ets b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/MethodCallHandlerImpl.ets index e7240b58ef56d4d73c903982a515f6dca1433760..25f7a9f94755c52e20614bece78da73330f263ae 100644 --- a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/MethodCallHandlerImpl.ets +++ b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/MethodCallHandlerImpl.ets @@ -156,7 +156,7 @@ export default class MethodCallHandlerImpl implements MethodCallHandler { } try { Log.d(TAG, "show-->request: " + JSON.stringify(notificationDetails)); - notificationManagerApi.showNotification(notificationDetails); + await notificationManagerApi.showNotification(notificationDetails); result.success(null); } catch (e) { result.error("-1", e, ""); diff --git a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/NotificationManager.ets b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/NotificationManager.ets index ea6d98114fc58b84202a34903c87cbbf0cdd47ea..24ad980ac8a1a0b3c1376d8cad509cf56af0cf37 100644 --- a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/NotificationManager.ets +++ b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/NotificationManager.ets @@ -475,14 +475,7 @@ class NotificationManager { let uiAbility: UIAbility | undefined = globalThis.context; let icon: Uint8Array | undefined = await uiAbility?.context.resourceManager.getMediaByName(defaultIcon); if (icon) { - let opts: image.InitializationOptions = { - size: { - height: LocalNotificationsConstants.SMALL_ICON_WIDTH, - width: LocalNotificationsConstants.SMALL_ICON_WIDTH - }, - pixelFormat: image.PixelMapFormat.RGBA_8888 - } - result.smallIcon = await image.createPixelMap(icon.buffer.slice(0), opts); + result.smallIcon = await image.createImageSource(icon.buffer).createPixelMap(); } } if (notificationDetails.largeIcon && notificationDetails.largeIconSource != undefined) { diff --git a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/models/NotificationDetails.ets b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/models/NotificationDetails.ets index 483feeb312380d71c94ba802200e898b0a3217c1..cb5ce0909cc9f0a789e690afa83d66242bff1580 100644 --- a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/models/NotificationDetails.ets +++ b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/models/NotificationDetails.ets @@ -143,12 +143,23 @@ export default class NotificationDetails { notificationDetails.enableVibration = platformChannelSpecifics.get(LocalNotificationsConstants.ENABLE_VIBRATION) as (boolean | undefined); notificationDetails.vibrationPattern = platformChannelSpecifics.get(LocalNotificationsConstants.VIBRATION_PATTERN) as (Array | undefined); notificationDetails.enableLights = platformChannelSpecifics.get(LocalNotificationsConstants.ENABLE_LIGHTS) as (boolean | undefined); - let alpha: number | undefined = call.argument(LocalNotificationsConstants.LED_COLOR_ALPHA); - let red: number | undefined = call.argument(LocalNotificationsConstants.LED_COLOR_RED); - let green: number | undefined = call.argument(LocalNotificationsConstants.LED_COLOR_GREEN); - let blue: number | undefined = call.argument(LocalNotificationsConstants.LED_COLOR_BLUE); - if (alpha && red && green && blue) { - notificationDetails.ledColor = (alpha << 24) | (red << 16) | (green << 8) | blue; + notificationDetails.colorized = platformChannelSpecifics.get(LocalNotificationsConstants.COLORIZED) as (boolean | undefined); + let alpha: number | undefined = platformChannelSpecifics.get(LocalNotificationsConstants.LED_COLOR_ALPHA) as (number | undefined); + let red: number | undefined = platformChannelSpecifics.get(LocalNotificationsConstants.LED_COLOR_RED) as (number | undefined); + let green: number | undefined = platformChannelSpecifics.get(LocalNotificationsConstants.LED_COLOR_GREEN) as (number | undefined); + let blue: number | undefined = platformChannelSpecifics.get(LocalNotificationsConstants.LED_COLOR_BLUE) as (number | undefined); + if (alpha != undefined && red!= undefined && green!= undefined && blue!= undefined) { + alpha = Math.max(0, Math.min(255, alpha)); + red = Math.max(0, Math.min(255, red)); + green = Math.max(0, Math.min(255, green)); + blue = Math.max(0, Math.min(255, blue)); + + let color: number = (alpha << 24) | (red << 16) | (green << 8) | blue; + if (color < 0) { + color = 0xFFFFFFFF + color + 1; + } + // TODO暂未支持 + // notificationDetails.color = color; } let silent = platformChannelSpecifics.get(LocalNotificationsConstants.SILENT) as (boolean | undefined); if (silent) { diff --git a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/utils/Utils.ets b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/utils/Utils.ets index b30daf4f970fcd0bc70b35a1bc34b78c6619da3d..bd5c99ee8d3df381906812657faa3809633d31c2 100644 --- a/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/utils/Utils.ets +++ b/flutter_local_notifications/ohos/src/main/ets/com/dexterous/flutterlocalnotifications/utils/Utils.ets @@ -29,11 +29,7 @@ export class Utils { if (pictureSource == PictureSource.DrawableResource) { let pictureArray: Uint8Array | undefined = await uiAbility?.context.resourceManager.getMediaByName(String(data)); if (pictureArray) { - let opts: image.InitializationOptions = { - size: { height: height, width: width }, - pixelFormat: image.PixelMapFormat.RGBA_8888 - } - picPixelMap = await image.createPixelMap(pictureArray.buffer.slice(0), opts); + picPixelMap = await image.createImageSource(pictureArray).createPixelMap(); } } else if (pictureSource == PictureSource.FilePath) { let path = String(data); @@ -41,11 +37,7 @@ export class Utils { let file: fs.File = await fs.open(path); let arrayBuffer = new ArrayBuffer(stat.size); await fs.read(file.fd, arrayBuffer); - let opts: image.InitializationOptions = { - size: { height: height, width: width }, - pixelFormat: image.PixelMapFormat.RGBA_8888 - } - picPixelMap = await image.createPixelMap(arrayBuffer, opts); + picPixelMap = await image.createImageSource(arrayBuffer).createPixelMap(); } else if (pictureSource == PictureSource.ByteArray) { let dataArray = data as Uint8Array; let imageSource: image.ImageSource = image.createImageSource(dataArray.buffer.slice(0)); diff --git a/flutter_local_notifications/ohos/src/main/module.json5 b/flutter_local_notifications/ohos/src/main/module.json5 index 8d7a308b5cce964f21617d450a3142f5b7687c42..369124b7022ed1610908b057227c91ee62c9bb76 100644 --- a/flutter_local_notifications/ohos/src/main/module.json5 +++ b/flutter_local_notifications/ohos/src/main/module.json5 @@ -7,6 +7,9 @@ "tablet" ], "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, { "name": "ohos.permission.PUBLISH_AGENT_REMINDER", "usedScene": { diff --git a/flutter_local_notifications/ohos/src/main/resources/base/media/sample_large_icon.png b/flutter_local_notifications/ohos/src/main/resources/base/media/sample_large_icon.png index f354ca234d31b0d663336c154933042eb1513bdb..c873f039d046c4766a12007c0211578d9994d862 100644 Binary files a/flutter_local_notifications/ohos/src/main/resources/base/media/sample_large_icon.png and b/flutter_local_notifications/ohos/src/main/resources/base/media/sample_large_icon.png differ