From b54031b1bb180cda187f2dee323450d1f77db82b Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 30 Nov 2025 13:54:44 +1100 Subject: [PATCH 1/9] bumped minimum Flutter and Dart versions to 3.32 and 3.8 respectively --- flutter_local_notifications/example/pubspec.yaml | 4 ++-- flutter_local_notifications/pubspec.yaml | 4 ++-- flutter_local_notifications_linux/pubspec.yaml | 4 ++-- flutter_local_notifications_platform_interface/pubspec.yaml | 4 ++-- flutter_local_notifications_windows/pubspec.yaml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/flutter_local_notifications/example/pubspec.yaml b/flutter_local_notifications/example/pubspec.yaml index 21edacde6..b4bceb57b 100644 --- a/flutter_local_notifications/example/pubspec.yaml +++ b/flutter_local_notifications/example/pubspec.yaml @@ -31,8 +31,8 @@ flutter: - sound/ environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.8.0 + flutter: ">=3.32.0" msix_config: display_name: Flutter Local Notifications Example diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index b44c26609..68de274be 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -42,5 +42,5 @@ flutter: default_package: flutter_local_notifications_windows environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.8.0 + flutter: ">=3.32.0" diff --git a/flutter_local_notifications_linux/pubspec.yaml b/flutter_local_notifications_linux/pubspec.yaml index 1c0b4f1cd..c113aa1f7 100644 --- a/flutter_local_notifications_linux/pubspec.yaml +++ b/flutter_local_notifications_linux/pubspec.yaml @@ -28,5 +28,5 @@ dev_dependencies: mockito: ^5.3.2 environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.8.0 + flutter: ">=3.32.0" diff --git a/flutter_local_notifications_platform_interface/pubspec.yaml b/flutter_local_notifications_platform_interface/pubspec.yaml index f598f657d..4d923bf31 100644 --- a/flutter_local_notifications_platform_interface/pubspec.yaml +++ b/flutter_local_notifications_platform_interface/pubspec.yaml @@ -5,8 +5,8 @@ homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flut issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.8.0 + flutter: ">=3.32.0" dependencies: plugin_platform_interface: ^2.1.8 diff --git a/flutter_local_notifications_windows/pubspec.yaml b/flutter_local_notifications_windows/pubspec.yaml index 0e623ccab..cc1c2642c 100644 --- a/flutter_local_notifications_windows/pubspec.yaml +++ b/flutter_local_notifications_windows/pubspec.yaml @@ -5,8 +5,8 @@ homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flut issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.8.0 + flutter: ">=3.32.0" dependencies: flutter: From 4447f01756a0417a026a4192e5b625c143d7f856 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 30 Nov 2025 13:55:02 +1100 Subject: [PATCH 2/9] added iOS example app runner changes --- .../Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flutter_local_notifications/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/flutter_local_notifications/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 8e3ca5dfe..e3773d42e 100644 --- a/flutter_local_notifications/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/flutter_local_notifications/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -26,6 +26,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit" shouldUseLaunchSchemeArgsEnv = "YES"> From 909b1a2d158fe63050463759fce3a1eea7ad6179 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 30 Nov 2025 14:14:06 +1100 Subject: [PATCH 3/9] fixed colour deprecation warnings --- .../android/method_channel_mappers.dart | 315 +++++++++--------- 1 file changed, 165 insertions(+), 150 deletions(-) diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart b/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart index bd4bbabb3..a34ec131b 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/method_channel_mappers.dart @@ -1,3 +1,5 @@ +import 'dart:ui'; + import 'enums.dart'; import 'initialization_settings.dart'; import 'message.dart'; @@ -20,48 +22,57 @@ extension AndroidInitializationSettingsMapper on AndroidInitializationSettings { extension MessageMapper on Message { Map toMap() => { - 'text': text, - 'timestamp': timestamp.millisecondsSinceEpoch, - 'person': person?.toMap(), - 'dataMimeType': dataMimeType, - 'dataUri': dataUri - }; + 'text': text, + 'timestamp': timestamp.millisecondsSinceEpoch, + 'person': person?.toMap(), + 'dataMimeType': dataMimeType, + 'dataUri': dataUri, + }; } extension AndroidNotificationChannelGroupMapper on AndroidNotificationChannelGroup { Map toMap() => { - 'id': id, - 'name': name, - 'description': description, - }; + 'id': id, + 'name': name, + 'description': description, + }; } extension AndroidNotificationChannelMapper on AndroidNotificationChannel { Map toMap() => { - 'id': id, - 'name': name, - 'description': description, - 'groupId': groupId, - 'showBadge': showBadge, - 'importance': importance.value, - 'bypassDnd': bypassDnd, - 'playSound': playSound, - 'enableVibration': enableVibration, - 'vibrationPattern': vibrationPattern, - 'enableLights': enableLights, - 'ledColorAlpha': ledColor?.alpha, - 'ledColorRed': ledColor?.red, - 'ledColorGreen': ledColor?.green, - 'ledColorBlue': ledColor?.blue, - 'audioAttributesUsage': audioAttributesUsage.value, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - }..addAll(_convertNotificationSoundToMap(sound)); + 'id': id, + 'name': name, + 'description': description, + 'groupId': groupId, + 'showBadge': showBadge, + 'importance': importance.value, + 'bypassDnd': bypassDnd, + 'playSound': playSound, + 'enableVibration': enableVibration, + 'vibrationPattern': vibrationPattern, + 'enableLights': enableLights, + 'ledColorAlpha': ledColor?.intAlpha, + 'ledColorRed': ledColor?.intRed, + 'ledColorGreen': ledColor?.intGreen, + 'ledColorBlue': ledColor?.intBlue, + 'audioAttributesUsage': audioAttributesUsage.value, + 'channelAction': AndroidNotificationChannelAction.createIfNotExists.index, + }..addAll(_convertNotificationSoundToMap(sound)); +} + +extension IntColorComponents on Color { + int get intAlpha => _floatToInt8(a); + int get intRed => _floatToInt8(r); + int get intGreen => _floatToInt8(g); + int get intBlue => _floatToInt8(b); + + int _floatToInt8(double x) => (x * 255.0).round() & 0xff; } Map _convertNotificationSoundToMap( - AndroidNotificationSound? sound) { + AndroidNotificationSound? sound, +) { if (sound is RawResourceAndroidNotificationSound) { return { 'sound': sound.sound, @@ -79,12 +90,12 @@ Map _convertNotificationSoundToMap( extension PersonMapper on Person { Map toMap() => { - 'bot': bot, - 'important': important, - 'key': key, - 'name': name, - 'uri': uri - }..addAll(_convertIconToMap()); + 'bot': bot, + 'important': important, + 'key': key, + 'name': name, + 'uri': uri, + }..addAll(_convertIconToMap()); Map _convertIconToMap() { if (icon == null) { @@ -102,11 +113,11 @@ extension DefaultStyleInformationMapper on DefaultStyleInformation { } Map _convertDefaultStyleInformationToMap( - DefaultStyleInformation styleInformation) => - { - 'htmlFormatContent': styleInformation.htmlFormatContent, - 'htmlFormatTitle': styleInformation.htmlFormatTitle - }; + DefaultStyleInformation styleInformation, +) => { + 'htmlFormatContent': styleInformation.htmlFormatContent, + 'htmlFormatTitle': styleInformation.htmlFormatTitle, +}; extension BigPictureStyleInformationMapper on BigPictureStyleInformation { Map toMap() => _convertDefaultStyleInformationToMap(this) @@ -117,13 +128,13 @@ extension BigPictureStyleInformationMapper on BigPictureStyleInformation { 'summaryText': summaryText, 'htmlFormatContentTitle': htmlFormatContentTitle, 'htmlFormatSummaryText': htmlFormatSummaryText, - 'hideExpandedLargeIcon': hideExpandedLargeIcon + 'hideExpandedLargeIcon': hideExpandedLargeIcon, }); Map _convertBigPictureToMap() => { - 'bigPicture': bigPicture.data, - 'bigPictureBitmapSource': bigPicture.source.index, - }; + 'bigPicture': bigPicture.data, + 'bigPictureBitmapSource': bigPicture.source.index, + }; Map _convertLargeIconToMap() { if (largeIcon == null) { @@ -137,94 +148,95 @@ extension BigPictureStyleInformationMapper on BigPictureStyleInformation { } extension BigTexStyleInformationMapper on BigTextStyleInformation { - Map toMap() => _convertDefaultStyleInformationToMap(this) - ..addAll({ - 'bigText': bigText, - 'htmlFormatBigText': htmlFormatBigText, - 'contentTitle': contentTitle, - 'htmlFormatContentTitle': htmlFormatContentTitle, - 'summaryText': summaryText, - 'htmlFormatSummaryText': htmlFormatSummaryText - }); + Map toMap() => + _convertDefaultStyleInformationToMap(this)..addAll({ + 'bigText': bigText, + 'htmlFormatBigText': htmlFormatBigText, + 'contentTitle': contentTitle, + 'htmlFormatContentTitle': htmlFormatContentTitle, + 'summaryText': summaryText, + 'htmlFormatSummaryText': htmlFormatSummaryText, + }); } extension InboxStyleInformationMapper on InboxStyleInformation { - Map toMap() => _convertDefaultStyleInformationToMap(this) - ..addAll({ - 'contentTitle': contentTitle, - 'htmlFormatContentTitle': htmlFormatContentTitle, - 'summaryText': summaryText, - 'htmlFormatSummaryText': htmlFormatSummaryText, - 'lines': lines, - 'htmlFormatLines': htmlFormatLines - }); + Map toMap() => + _convertDefaultStyleInformationToMap(this)..addAll({ + 'contentTitle': contentTitle, + 'htmlFormatContentTitle': htmlFormatContentTitle, + 'summaryText': summaryText, + 'htmlFormatSummaryText': htmlFormatSummaryText, + 'lines': lines, + 'htmlFormatLines': htmlFormatLines, + }); } extension MessagingStyleInformationMapper on MessagingStyleInformation { - Map toMap() => _convertDefaultStyleInformationToMap(this) - ..addAll({ - 'person': person.toMap(), - 'conversationTitle': conversationTitle, - 'groupConversation': groupConversation, - 'messages': messages - ?.map((m) => m.toMap()) // ignore: always_specify_types - .toList() - }); + Map toMap() => + _convertDefaultStyleInformationToMap(this)..addAll({ + 'person': person.toMap(), + 'conversationTitle': conversationTitle, + 'groupConversation': groupConversation, + 'messages': messages + ?.map((m) => m.toMap()) // ignore: always_specify_types + .toList(), + }); } extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { - Map toMap() => { - 'icon': icon, - 'channelId': channelId, - 'channelName': channelName, - 'channelDescription': channelDescription, - 'channelShowBadge': channelShowBadge, - 'channelAction': channelAction.index, - 'importance': importance.value, - 'channelBypassDnd': channelBypassDnd, - 'priority': priority.value, - 'playSound': playSound, - 'enableVibration': enableVibration, - 'vibrationPattern': vibrationPattern, - 'groupKey': groupKey, - 'setAsGroupSummary': setAsGroupSummary, - 'groupAlertBehavior': groupAlertBehavior.index, - 'autoCancel': autoCancel, - 'ongoing': ongoing, - 'silent': silent, - 'colorAlpha': color?.alpha, - 'colorRed': color?.red, - 'colorGreen': color?.green, - 'colorBlue': color?.blue, - 'onlyAlertOnce': onlyAlertOnce, - 'showWhen': showWhen, - 'when': when, - 'usesChronometer': usesChronometer, - 'chronometerCountDown': chronometerCountDown, - 'showProgress': showProgress, - 'maxProgress': maxProgress, - 'progress': progress, - 'indeterminate': indeterminate, - 'enableLights': enableLights, - 'ledColorAlpha': ledColor?.alpha, - 'ledColorRed': ledColor?.red, - 'ledColorGreen': ledColor?.green, - 'ledColorBlue': ledColor?.blue, - 'ledOnMs': ledOnMs, - 'ledOffMs': ledOffMs, - 'ticker': ticker, - 'visibility': visibility?.index, - 'timeoutAfter': timeoutAfter, - 'category': category?.name, - 'fullScreenIntent': fullScreenIntent, - 'shortcutId': shortcutId, - 'additionalFlags': additionalFlags, - 'subText': subText, - 'tag': tag, - 'colorized': colorized, - 'number': number, - 'audioAttributesUsage': audioAttributesUsage.value, - } + Map toMap() => + { + 'icon': icon, + 'channelId': channelId, + 'channelName': channelName, + 'channelDescription': channelDescription, + 'channelShowBadge': channelShowBadge, + 'channelAction': channelAction.index, + 'importance': importance.value, + 'channelBypassDnd': channelBypassDnd, + 'priority': priority.value, + 'playSound': playSound, + 'enableVibration': enableVibration, + 'vibrationPattern': vibrationPattern, + 'groupKey': groupKey, + 'setAsGroupSummary': setAsGroupSummary, + 'groupAlertBehavior': groupAlertBehavior.index, + 'autoCancel': autoCancel, + 'ongoing': ongoing, + 'silent': silent, + 'colorAlpha': color?.intAlpha, + 'colorRed': color?.intRed, + 'colorGreen': color?.intGreen, + 'colorBlue': color?.intBlue, + 'onlyAlertOnce': onlyAlertOnce, + 'showWhen': showWhen, + 'when': when, + 'usesChronometer': usesChronometer, + 'chronometerCountDown': chronometerCountDown, + 'showProgress': showProgress, + 'maxProgress': maxProgress, + 'progress': progress, + 'indeterminate': indeterminate, + 'enableLights': enableLights, + 'ledColorAlpha': ledColor?.intAlpha, + 'ledColorRed': ledColor?.intRed, + 'ledColorGreen': ledColor?.intGreen, + 'ledColorBlue': ledColor?.intBlue, + 'ledOnMs': ledOnMs, + 'ledOffMs': ledOffMs, + 'ticker': ticker, + 'visibility': visibility?.index, + 'timeoutAfter': timeoutAfter, + 'category': category?.name, + 'fullScreenIntent': fullScreenIntent, + 'shortcutId': shortcutId, + 'additionalFlags': additionalFlags, + 'subText': subText, + 'tag': tag, + 'colorized': colorized, + 'number': number, + 'audioAttributesUsage': audioAttributesUsage.value, + } ..addAll(_convertActionsToMap(actions)) ..addAll(_convertStyleInformationToMap()) ..addAll(_convertNotificationSoundToMap(sound)) @@ -234,38 +246,38 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { if (styleInformation is BigPictureStyleInformation) { return { 'style': AndroidNotificationStyle.bigPicture.index, - 'styleInformation': - (styleInformation as BigPictureStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as BigPictureStyleInformation?) + ?.toMap(), }; } else if (styleInformation is BigTextStyleInformation) { return { 'style': AndroidNotificationStyle.bigText.index, - 'styleInformation': - (styleInformation as BigTextStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as BigTextStyleInformation?) + ?.toMap(), }; } else if (styleInformation is InboxStyleInformation) { return { 'style': AndroidNotificationStyle.inbox.index, - 'styleInformation': - (styleInformation as InboxStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as InboxStyleInformation?) + ?.toMap(), }; } else if (styleInformation is MessagingStyleInformation) { return { 'style': AndroidNotificationStyle.messaging.index, - 'styleInformation': - (styleInformation as MessagingStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as MessagingStyleInformation?) + ?.toMap(), }; } else if (styleInformation is MediaStyleInformation) { return { 'style': AndroidNotificationStyle.media.index, - 'styleInformation': - (styleInformation as MediaStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as MediaStyleInformation?) + ?.toMap(), }; } else if (styleInformation is DefaultStyleInformation) { return { 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': - (styleInformation as DefaultStyleInformation?)?.toMap(), + 'styleInformation': (styleInformation as DefaultStyleInformation?) + ?.toMap(), }; } else { return { @@ -286,7 +298,8 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { } Map _convertActionsToMap( - List? actions) { + List? actions, + ) { if (actions == null) { return {}; } @@ -296,10 +309,10 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { (AndroidNotificationAction e) => { 'id': e.id, 'title': e.title, - 'titleColorAlpha': e.titleColor?.alpha, - 'titleColorRed': e.titleColor?.red, - 'titleColorGreen': e.titleColor?.green, - 'titleColorBlue': e.titleColor?.blue, + 'titleColorAlpha': e.titleColor?.intAlpha, + 'titleColorRed': e.titleColor?.intRed, + 'titleColorGreen': e.titleColor?.intGreen, + 'titleColorBlue': e.titleColor?.intBlue, if (e.icon != null) ...{ 'icon': e.icon!.data, 'iconBitmapSource': e.icon!.source.index, @@ -308,8 +321,10 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { 'showsUserInterface': e.showsUserInterface, 'allowGeneratedReplies': e.allowGeneratedReplies, 'inputs': e.inputs - .map((AndroidNotificationActionInput input) => - _convertInputToMap(input)) + .map( + (AndroidNotificationActionInput input) => + _convertInputToMap(input), + ) .toList(), 'cancelNotification': e.cancelNotification, 'semanticAction': e.semanticAction.value, @@ -321,11 +336,11 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails { } Map _convertInputToMap( - AndroidNotificationActionInput input) => - { - 'choices': input.choices, - 'allowFreeFormInput': input.allowFreeFormInput, - 'label': input.label, - 'allowedMimeType': input.allowedMimeTypes.toList(), - }; + AndroidNotificationActionInput input, + ) => { + 'choices': input.choices, + 'allowFreeFormInput': input.allowFreeFormInput, + 'label': input.label, + 'allowedMimeType': input.allowedMimeTypes.toList(), + }; } From 6c72c36c97b328baba936c8d7e3509d9fb7a9105 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 30 Nov 2025 14:56:58 +1100 Subject: [PATCH 4/9] updated changelog and pubspec files for upcoming prerelease --- flutter_local_notifications/CHANGELOG.md | 4 +++- flutter_local_notifications/pubspec.yaml | 8 ++++---- flutter_local_notifications_linux/CHANGELOG.md | 4 ++++ flutter_local_notifications_linux/pubspec.yaml | 4 ++-- .../CHANGELOG.md | 4 ++++ .../pubspec.yaml | 2 +- flutter_local_notifications_windows/CHANGELOG.md | 2 +- flutter_local_notifications_windows/pubspec.yaml | 4 ++-- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index c2bf4490f..1667d6681 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,5 +1,7 @@ -## [vNext] +## [20.0.0-dev.1] +* **Breaking change** bumped minimum Flutter SDK requirement to 3.32.0 and Dart SDK requirement to 3.8.0 +* [Windows] **Breaking change** removed the `details` parameter from the `zonedScheduleRawXml()` method as it was not actually used. Thanks to the PR from [Levi Lesches](https://github.com/Levi-Lesches) * Updated readme with information for developers that plan to move to use the UIScene lifecycle ## [19.5.0] diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index 68de274be..7ad7c7a04 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_local_notifications description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform. -version: 19.5.0 +version: 20.0.0-dev.1 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues @@ -10,9 +10,9 @@ dependencies: clock: ^1.1.0 flutter: sdk: flutter - flutter_local_notifications_linux: ^6.0.0 - flutter_local_notifications_windows: ^1.0.3 - flutter_local_notifications_platform_interface: ^9.1.0 + flutter_local_notifications_linux: ^7.0.0-dev.1 + flutter_local_notifications_windows: ^2.0.0-dev.1 + flutter_local_notifications_platform_interface: ^10.0.0-dev.1 timezone: ^0.10.0 dev_dependencies: diff --git a/flutter_local_notifications_linux/CHANGELOG.md b/flutter_local_notifications_linux/CHANGELOG.md index aade7234d..2d0fb5880 100644 --- a/flutter_local_notifications_linux/CHANGELOG.md +++ b/flutter_local_notifications_linux/CHANGELOG.md @@ -1,3 +1,7 @@ +## [7.0.0-dev.1] + +* **Breaking change** bumped minimum Flutter SDK requirement to 3.32.0 and Dart SDK requirement to 3.8.0 + ## [6.0.0] * **Breaking change** bumped minimum Flutter SDK requirement to 3.22.0 and Dart SDK requirement to 3.4.0 diff --git a/flutter_local_notifications_linux/pubspec.yaml b/flutter_local_notifications_linux/pubspec.yaml index c113aa1f7..abeb02cc7 100644 --- a/flutter_local_notifications_linux/pubspec.yaml +++ b/flutter_local_notifications_linux/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications_linux description: Linux implementation of the flutter_local_notifications plugin -version: 6.0.0 +version: 7.0.0-dev.1 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues @@ -17,7 +17,7 @@ dependencies: ffi: ^2.0.1 flutter: sdk: flutter - flutter_local_notifications_platform_interface: ^9.0.0 + flutter_local_notifications_platform_interface: ^10.0.0-dev.1 path: ^1.8.0 xdg_directories: ">=0.2.0+1 <2.0.0" diff --git a/flutter_local_notifications_platform_interface/CHANGELOG.md b/flutter_local_notifications_platform_interface/CHANGELOG.md index c94648e43..1115b73f2 100644 --- a/flutter_local_notifications_platform_interface/CHANGELOG.md +++ b/flutter_local_notifications_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## [10.0.0-dev.1] + +* **Breaking change** bumped minimum Flutter SDK requirement to 3.32.0 and Dart SDK requirement to 3.8.0 + ## [9.1.0] * Added `cancelAllPendingNotifications()` method for cancelling all pending notifications that have been scheduled. Thanks to the PR from [Kwon Tae Hyung](https://github.com/TaeBbong) diff --git a/flutter_local_notifications_platform_interface/pubspec.yaml b/flutter_local_notifications_platform_interface/pubspec.yaml index 4d923bf31..5a2c6cc22 100644 --- a/flutter_local_notifications_platform_interface/pubspec.yaml +++ b/flutter_local_notifications_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications_platform_interface description: A common platform interface for the flutter_local_notifications plugin. -version: 9.1.0 +version: 10.0.0-dev.1 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications_platform_interface issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues diff --git a/flutter_local_notifications_windows/CHANGELOG.md b/flutter_local_notifications_windows/CHANGELOG.md index 19e085e42..dc0798c36 100644 --- a/flutter_local_notifications_windows/CHANGELOG.md +++ b/flutter_local_notifications_windows/CHANGELOG.md @@ -1,4 +1,4 @@ -## [vNext] +## [2.0.0-dev.1] * **Breaking change** removed the `details` parameter from the `zonedScheduleRawXml()` method as it was not actually used. Thanks to the PR from [Levi Lesches](https://github.com/Levi-Lesches) diff --git a/flutter_local_notifications_windows/pubspec.yaml b/flutter_local_notifications_windows/pubspec.yaml index cc1c2642c..c26265c41 100644 --- a/flutter_local_notifications_windows/pubspec.yaml +++ b/flutter_local_notifications_windows/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_local_notifications_windows description: Windows implementation of the flutter_local_notifications plugin -version: 1.0.3 +version: 2.0.0-dev.1 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications_windows issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues @@ -12,7 +12,7 @@ dependencies: flutter: sdk: flutter ffi: ^2.1.2 - flutter_local_notifications_platform_interface: ^9.0.0 + flutter_local_notifications_platform_interface: ^10.0.0-dev.1 meta: ^1.11.0 timezone: ^0.10.0 xml: ^6.5.0 From ff7c41f11c25ce1da7f336883d07e3dcb45d38d4 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 30 Nov 2025 16:14:35 +1100 Subject: [PATCH 5/9] update github actions that tested on 3.22.0 to 3.32.0 --- .github/workflows/validate.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 0bb09664c..1d93ba98b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -24,7 +24,7 @@ jobs: - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools @@ -67,7 +67,7 @@ jobs: - name: Build run: melos run build:example_android build_example_android_3_19: - name: Build Android example app (3.22) + name: Build Android example app (3.32) runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -78,7 +78,7 @@ jobs: - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools @@ -100,14 +100,14 @@ jobs: - name: Build run: melos run build:example_ios build_example_ios_3_19: - name: Build iOS example app (3.22) + name: Build iOS example app (3.32) runs-on: macos-latest steps: - uses: actions/checkout@v5 - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools @@ -129,14 +129,14 @@ jobs: - name: Build run: melos run build:example_macos build_example_macos_3_19: - name: Build macOS example app (3.22) + name: Build macOS example app (3.32) runs-on: macos-latest steps: - uses: actions/checkout@v5 - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools @@ -162,14 +162,14 @@ jobs: - name: Build run: melos run build:example_linux build_example_linux_3_19: - name: Build Linux example app (3.22) + name: Build Linux example app (3.32) runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools @@ -206,14 +206,14 @@ jobs: dart pub get dart run msix:create build_example_windows_3_19: - name: Build Windows example app (3.22) + name: Build Windows example app (3.32) runs-on: windows-latest steps: - uses: actions/checkout@v5 - uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.22.0 + flutter-version: 3.32.0 cache: true cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' - name: Install Tools From f3be915f9af45cde90ac85e78ce83d594b92709d Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:17:49 +1100 Subject: [PATCH 6/9] regenerated mocks for Linux plugin --- .../notifications_manager_test.mocks.dart | 1311 +++++++-------- .../test/storage_test.mocks.dart | 1414 ++++++++--------- 2 files changed, 1238 insertions(+), 1487 deletions(-) diff --git a/flutter_local_notifications_linux/test/notifications_manager_test.mocks.dart b/flutter_local_notifications_linux/test/notifications_manager_test.mocks.dart index a038b2b21..6054abcf8 100644 --- a/flutter_local_notifications_linux/test/notifications_manager_test.mocks.dart +++ b/flutter_local_notifications_linux/test/notifications_manager_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.6 from annotations // in flutter_local_notifications_linux/test/notifications_manager_test.dart. // Do not manually edit this file. @@ -8,36 +8,36 @@ import 'dart:async' as _i3; import 'package:dbus/dbus.dart' as _i2; import 'package:flutter_local_notifications_linux/src/dbus_wrapper.dart' as _i5; import 'package:flutter_local_notifications_linux/src/notification_info.dart' - as _i7; + as _i8; import 'package:flutter_local_notifications_linux/src/platform_info.dart' as _i4; -import 'package:flutter_local_notifications_linux/src/storage.dart' as _i6; +import 'package:flutter_local_notifications_linux/src/storage.dart' as _i7; import 'package:flutter_local_notifications_platform_interface/flutter_local_notifications_platform_interface.dart' - as _i9; + as _i10; import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i6; -import 'notifications_manager_test.dart' as _i8; +import 'notifications_manager_test.dart' as _i9; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: must_be_immutable // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeDBusMethodSuccessResponse_0 extends _i1.SmartFake implements _i2.DBusMethodSuccessResponse { - _FakeDBusMethodSuccessResponse_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeDBusMethodSuccessResponse_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeDBusRemoteObjectSignalStream_1 extends _i1.SmartFake @@ -45,52 +45,29 @@ class _FakeDBusRemoteObjectSignalStream_1 extends _i1.SmartFake _FakeDBusRemoteObjectSignalStream_1( Object parent, Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + ) : super(parent, parentInvocation); } class _FakeDBusSignal_2 extends _i1.SmartFake implements _i2.DBusSignal { - _FakeDBusSignal_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeDBusSignal_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeStreamSubscription_3 extends _i1.SmartFake implements _i3.StreamSubscription { - _FakeStreamSubscription_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeStreamSubscription_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeFuture_4 extends _i1.SmartFake implements _i3.Future { - _FakeFuture_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeFuture_4(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeLinuxPlatformInfoData_5 extends _i1.SmartFake implements _i4.LinuxPlatformInfoData { - _FakeLinuxPlatformInfoData_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeLinuxPlatformInfoData_5(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } /// A class which mocks [DBusWrapper]. @@ -98,21 +75,12 @@ class _FakeLinuxPlatformInfoData_5 extends _i1.SmartFake /// See the documentation for Mockito's code generation for more information. class MockDBusWrapper extends _i1.Mock implements _i5.DBusWrapper { @override - void build({ - required String? destination, - required String? path, - }) => + void build({required String? destination, required String? path}) => super.noSuchMethod( - Invocation.method( - #build, - [], - { - #destination: destination, - #path: path, - }, - ), + Invocation.method(#build, [], {#destination: destination, #path: path}), returnValueForMissingStub: null, ); + @override _i3.Future<_i2.DBusMethodSuccessResponse> callMethod( String? interface, @@ -124,80 +92,66 @@ class MockDBusWrapper extends _i1.Mock implements _i5.DBusWrapper { bool? allowInteractiveAuthorization = false, }) => (super.noSuchMethod( - Invocation.method( - #callMethod, - [ - interface, - name, - values, - ], - { - #replySignature: replySignature, - #noReplyExpected: noReplyExpected, - #noAutoStart: noAutoStart, - #allowInteractiveAuthorization: allowInteractiveAuthorization, - }, - ), - returnValue: _i3.Future<_i2.DBusMethodSuccessResponse>.value( - _FakeDBusMethodSuccessResponse_0( - this, - Invocation.method( - #callMethod, - [ - interface, - name, - values, - ], - { - #replySignature: replySignature, - #noReplyExpected: noReplyExpected, - #noAutoStart: noAutoStart, - #allowInteractiveAuthorization: allowInteractiveAuthorization, - }, - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusMethodSuccessResponse>.value( - _FakeDBusMethodSuccessResponse_0( - this, - Invocation.method( - #callMethod, - [ - interface, - name, - values, - ], - { - #replySignature: replySignature, - #noReplyExpected: noReplyExpected, - #noAutoStart: noAutoStart, - #allowInteractiveAuthorization: allowInteractiveAuthorization, - }, - ), - )), - ) as _i3.Future<_i2.DBusMethodSuccessResponse>); + Invocation.method( + #callMethod, + [interface, name, values], + { + #replySignature: replySignature, + #noReplyExpected: noReplyExpected, + #noAutoStart: noAutoStart, + #allowInteractiveAuthorization: allowInteractiveAuthorization, + }, + ), + returnValue: _i3.Future<_i2.DBusMethodSuccessResponse>.value( + _FakeDBusMethodSuccessResponse_0( + this, + Invocation.method( + #callMethod, + [interface, name, values], + { + #replySignature: replySignature, + #noReplyExpected: noReplyExpected, + #noAutoStart: noAutoStart, + #allowInteractiveAuthorization: + allowInteractiveAuthorization, + }, + ), + ), + ), + returnValueForMissingStub: + _i3.Future<_i2.DBusMethodSuccessResponse>.value( + _FakeDBusMethodSuccessResponse_0( + this, + Invocation.method( + #callMethod, + [interface, name, values], + { + #replySignature: replySignature, + #noReplyExpected: noReplyExpected, + #noAutoStart: noAutoStart, + #allowInteractiveAuthorization: + allowInteractiveAuthorization, + }, + ), + ), + ), + ) + as _i3.Future<_i2.DBusMethodSuccessResponse>); + @override _i2.DBusRemoteObjectSignalStream subscribeSignal(String? name) => (super.noSuchMethod( - Invocation.method( - #subscribeSignal, - [name], - ), - returnValue: _FakeDBusRemoteObjectSignalStream_1( - this, - Invocation.method( - #subscribeSignal, - [name], - ), - ), - returnValueForMissingStub: _FakeDBusRemoteObjectSignalStream_1( - this, - Invocation.method( - #subscribeSignal, - [name], - ), - ), - ) as _i2.DBusRemoteObjectSignalStream); + Invocation.method(#subscribeSignal, [name]), + returnValue: _FakeDBusRemoteObjectSignalStream_1( + this, + Invocation.method(#subscribeSignal, [name]), + ), + returnValueForMissingStub: _FakeDBusRemoteObjectSignalStream_1( + this, + Invocation.method(#subscribeSignal, [name]), + ), + ) + as _i2.DBusRemoteObjectSignalStream); } /// A class which mocks [DBusRemoteObjectSignalStream]. @@ -206,62 +160,71 @@ class MockDBusWrapper extends _i1.Mock implements _i5.DBusWrapper { class MockDBusRemoteObjectSignalStream extends _i1.Mock implements _i2.DBusRemoteObjectSignalStream { @override - bool get isBroadcast => (super.noSuchMethod( - Invocation.getter(#isBroadcast), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - _i3.Future get length => (super.noSuchMethod( - Invocation.getter(#length), - returnValue: _i3.Future.value(0), - returnValueForMissingStub: _i3.Future.value(0), - ) as _i3.Future); - @override - _i3.Future get isEmpty => (super.noSuchMethod( - Invocation.getter(#isEmpty), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future<_i2.DBusSignal> get first => (super.noSuchMethod( - Invocation.getter(#first), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#first), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#first), - )), - ) as _i3.Future<_i2.DBusSignal>); - @override - _i3.Future<_i2.DBusSignal> get last => (super.noSuchMethod( - Invocation.getter(#last), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#last), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#last), - )), - ) as _i3.Future<_i2.DBusSignal>); - @override - _i3.Future<_i2.DBusSignal> get single => (super.noSuchMethod( - Invocation.getter(#single), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#single), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.getter(#single), - )), - ) as _i3.Future<_i2.DBusSignal>); + bool get isBroadcast => + (super.noSuchMethod( + Invocation.getter(#isBroadcast), + returnValue: false, + returnValueForMissingStub: false, + ) + as bool); + + @override + _i3.Future get length => + (super.noSuchMethod( + Invocation.getter(#length), + returnValue: _i3.Future.value(0), + returnValueForMissingStub: _i3.Future.value(0), + ) + as _i3.Future); + + @override + _i3.Future get isEmpty => + (super.noSuchMethod( + Invocation.getter(#isEmpty), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future<_i2.DBusSignal> get first => + (super.noSuchMethod( + Invocation.getter(#first), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#first)), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#first)), + ), + ) + as _i3.Future<_i2.DBusSignal>); + + @override + _i3.Future<_i2.DBusSignal> get last => + (super.noSuchMethod( + Invocation.getter(#last), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#last)), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#last)), + ), + ) + as _i3.Future<_i2.DBusSignal>); + + @override + _i3.Future<_i2.DBusSignal> get single => + (super.noSuchMethod( + Invocation.getter(#single), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#single)), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.getter(#single)), + ), + ) + as _i3.Future<_i2.DBusSignal>); + @override _i3.StreamSubscription<_i2.DBusSignal> listen( void Function(_i2.DBusSignal)? onData, { @@ -270,482 +233,448 @@ class MockDBusRemoteObjectSignalStream extends _i1.Mock bool? cancelOnError, }) => (super.noSuchMethod( - Invocation.method( - #listen, - [onData], - { - #onError: onError, - #onDone: onDone, - #cancelOnError: cancelOnError, - }, - ), - returnValue: _FakeStreamSubscription_3<_i2.DBusSignal>( - this, - Invocation.method( - #listen, - [onData], - { - #onError: onError, - #onDone: onDone, - #cancelOnError: cancelOnError, - }, - ), - ), - returnValueForMissingStub: _FakeStreamSubscription_3<_i2.DBusSignal>( - this, - Invocation.method( - #listen, - [onData], - { - #onError: onError, - #onDone: onDone, - #cancelOnError: cancelOnError, - }, - ), - ), - ) as _i3.StreamSubscription<_i2.DBusSignal>); + Invocation.method( + #listen, + [onData], + { + #onError: onError, + #onDone: onDone, + #cancelOnError: cancelOnError, + }, + ), + returnValue: _FakeStreamSubscription_3<_i2.DBusSignal>( + this, + Invocation.method( + #listen, + [onData], + { + #onError: onError, + #onDone: onDone, + #cancelOnError: cancelOnError, + }, + ), + ), + returnValueForMissingStub: + _FakeStreamSubscription_3<_i2.DBusSignal>( + this, + Invocation.method( + #listen, + [onData], + { + #onError: onError, + #onDone: onDone, + #cancelOnError: cancelOnError, + }, + ), + ), + ) + as _i3.StreamSubscription<_i2.DBusSignal>); + @override _i3.Stream<_i2.DBusSignal> asBroadcastStream({ void Function(_i3.StreamSubscription<_i2.DBusSignal>)? onListen, void Function(_i3.StreamSubscription<_i2.DBusSignal>)? onCancel, }) => (super.noSuchMethod( - Invocation.method( - #asBroadcastStream, - [], - { - #onListen: onListen, - #onCancel: onCancel, - }, - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#asBroadcastStream, [], { + #onListen: onListen, + #onCancel: onCancel, + }), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Stream<_i2.DBusSignal> where(bool Function(_i2.DBusSignal)? test) => (super.noSuchMethod( - Invocation.method( - #where, - [test], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#where, [test]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Stream map(S Function(_i2.DBusSignal)? convert) => (super.noSuchMethod( - Invocation.method( - #map, - [convert], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); + Invocation.method(#map, [convert]), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + @override _i3.Stream asyncMap( - _i3.FutureOr Function(_i2.DBusSignal)? convert) => + _i3.FutureOr Function(_i2.DBusSignal)? convert, + ) => (super.noSuchMethod( - Invocation.method( - #asyncMap, - [convert], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); + Invocation.method(#asyncMap, [convert]), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + @override _i3.Stream asyncExpand( - _i3.Stream? Function(_i2.DBusSignal)? convert) => + _i3.Stream? Function(_i2.DBusSignal)? convert, + ) => (super.noSuchMethod( - Invocation.method( - #asyncExpand, - [convert], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); + Invocation.method(#asyncExpand, [convert]), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + @override _i3.Stream<_i2.DBusSignal> handleError( Function? onError, { bool Function(dynamic)? test, }) => (super.noSuchMethod( - Invocation.method( - #handleError, - [onError], - {#test: test}, - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#handleError, [onError], {#test: test}), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Stream expand(Iterable Function(_i2.DBusSignal)? convert) => (super.noSuchMethod( - Invocation.method( - #expand, - [convert], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); + Invocation.method(#expand, [convert]), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + @override _i3.Future pipe( - _i3.StreamConsumer<_i2.DBusSignal>? streamConsumer) => + _i3.StreamConsumer<_i2.DBusSignal>? streamConsumer, + ) => (super.noSuchMethod( - Invocation.method( - #pipe, - [streamConsumer], - ), - returnValue: _i3.Future.value(), - returnValueForMissingStub: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#pipe, [streamConsumer]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); + @override _i3.Stream transform( - _i3.StreamTransformer<_i2.DBusSignal, S>? streamTransformer) => + _i3.StreamTransformer<_i2.DBusSignal, S>? streamTransformer, + ) => (super.noSuchMethod( - Invocation.method( - #transform, - [streamTransformer], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); + Invocation.method(#transform, [streamTransformer]), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + @override _i3.Future<_i2.DBusSignal> reduce( - _i2.DBusSignal Function( - _i2.DBusSignal, - _i2.DBusSignal, - )? combine) => - (super.noSuchMethod( - Invocation.method( - #reduce, - [combine], - ), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #reduce, - [combine], - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #reduce, - [combine], - ), - )), - ) as _i3.Future<_i2.DBusSignal>); + _i2.DBusSignal Function(_i2.DBusSignal, _i2.DBusSignal)? combine, + ) => + (super.noSuchMethod( + Invocation.method(#reduce, [combine]), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.method(#reduce, [combine])), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.method(#reduce, [combine])), + ), + ) + as _i3.Future<_i2.DBusSignal>); + @override _i3.Future fold( S? initialValue, - S Function( - S, - _i2.DBusSignal, - )? combine, + S Function(S, _i2.DBusSignal)? combine, ) => (super.noSuchMethod( - Invocation.method( - #fold, - [ - initialValue, - combine, - ], - ), - returnValue: _FakeFuture_4( - this, - Invocation.method( - #fold, - [ - initialValue, - combine, - ], - ), - ), - returnValueForMissingStub: _FakeFuture_4( - this, - Invocation.method( - #fold, - [ - initialValue, - combine, - ], - ), - ), - ) as _i3.Future); - @override - _i3.Future join([String? separator = r'']) => (super.noSuchMethod( - Invocation.method( - #join, - [separator], - ), - returnValue: _i3.Future.value(''), - returnValueForMissingStub: _i3.Future.value(''), - ) as _i3.Future); - @override - _i3.Future contains(Object? needle) => (super.noSuchMethod( - Invocation.method( - #contains, - [needle], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future forEach(void Function(_i2.DBusSignal)? action) => - (super.noSuchMethod( - Invocation.method( - #forEach, - [action], - ), - returnValue: _i3.Future.value(), - returnValueForMissingStub: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#fold, [initialValue, combine]), + returnValue: + _i6.ifNotNull( + _i6.dummyValueOrNull( + this, + Invocation.method(#fold, [initialValue, combine]), + ), + (S v) => _i3.Future.value(v), + ) ?? + _FakeFuture_4( + this, + Invocation.method(#fold, [initialValue, combine]), + ), + returnValueForMissingStub: + _i6.ifNotNull( + _i6.dummyValueOrNull( + this, + Invocation.method(#fold, [initialValue, combine]), + ), + (S v) => _i3.Future.value(v), + ) ?? + _FakeFuture_4( + this, + Invocation.method(#fold, [initialValue, combine]), + ), + ) + as _i3.Future); + + @override + _i3.Future join([String? separator = '']) => + (super.noSuchMethod( + Invocation.method(#join, [separator]), + returnValue: _i3.Future.value( + _i6.dummyValue( + this, + Invocation.method(#join, [separator]), + ), + ), + returnValueForMissingStub: _i3.Future.value( + _i6.dummyValue( + this, + Invocation.method(#join, [separator]), + ), + ), + ) + as _i3.Future); + + @override + _i3.Future contains(Object? needle) => + (super.noSuchMethod( + Invocation.method(#contains, [needle]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future forEach(void Function(_i2.DBusSignal)? action) => + (super.noSuchMethod( + Invocation.method(#forEach, [action]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); + @override _i3.Future every(bool Function(_i2.DBusSignal)? test) => (super.noSuchMethod( - Invocation.method( - #every, - [test], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); + Invocation.method(#every, [test]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + @override _i3.Future any(bool Function(_i2.DBusSignal)? test) => (super.noSuchMethod( - Invocation.method( - #any, - [test], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Stream cast() => (super.noSuchMethod( - Invocation.method( - #cast, - [], - ), - returnValue: _i3.Stream.empty(), - returnValueForMissingStub: _i3.Stream.empty(), - ) as _i3.Stream); - @override - _i3.Future> toList() => (super.noSuchMethod( - Invocation.method( - #toList, - [], - ), - returnValue: _i3.Future>.value(<_i2.DBusSignal>[]), - returnValueForMissingStub: - _i3.Future>.value(<_i2.DBusSignal>[]), - ) as _i3.Future>); - @override - _i3.Future> toSet() => (super.noSuchMethod( - Invocation.method( - #toSet, - [], - ), - returnValue: _i3.Future>.value(<_i2.DBusSignal>{}), - returnValueForMissingStub: - _i3.Future>.value(<_i2.DBusSignal>{}), - ) as _i3.Future>); - @override - _i3.Future drain([E? futureValue]) => (super.noSuchMethod( - Invocation.method( - #drain, - [futureValue], - ), - returnValue: _FakeFuture_4( - this, - Invocation.method( - #drain, - [futureValue], - ), - ), - returnValueForMissingStub: _FakeFuture_4( - this, - Invocation.method( - #drain, - [futureValue], - ), - ), - ) as _i3.Future); - @override - _i3.Stream<_i2.DBusSignal> take(int? count) => (super.noSuchMethod( - Invocation.method( - #take, - [count], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#any, [test]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Stream cast() => + (super.noSuchMethod( + Invocation.method(#cast, []), + returnValue: _i3.Stream.empty(), + returnValueForMissingStub: _i3.Stream.empty(), + ) + as _i3.Stream); + + @override + _i3.Future> toList() => + (super.noSuchMethod( + Invocation.method(#toList, []), + returnValue: _i3.Future>.value( + <_i2.DBusSignal>[], + ), + returnValueForMissingStub: _i3.Future>.value( + <_i2.DBusSignal>[], + ), + ) + as _i3.Future>); + + @override + _i3.Future> toSet() => + (super.noSuchMethod( + Invocation.method(#toSet, []), + returnValue: _i3.Future>.value( + <_i2.DBusSignal>{}, + ), + returnValueForMissingStub: _i3.Future>.value( + <_i2.DBusSignal>{}, + ), + ) + as _i3.Future>); + + @override + _i3.Future drain([E? futureValue]) => + (super.noSuchMethod( + Invocation.method(#drain, [futureValue]), + returnValue: + _i6.ifNotNull( + _i6.dummyValueOrNull( + this, + Invocation.method(#drain, [futureValue]), + ), + (E v) => _i3.Future.value(v), + ) ?? + _FakeFuture_4( + this, + Invocation.method(#drain, [futureValue]), + ), + returnValueForMissingStub: + _i6.ifNotNull( + _i6.dummyValueOrNull( + this, + Invocation.method(#drain, [futureValue]), + ), + (E v) => _i3.Future.value(v), + ) ?? + _FakeFuture_4( + this, + Invocation.method(#drain, [futureValue]), + ), + ) + as _i3.Future); + + @override + _i3.Stream<_i2.DBusSignal> take(int? count) => + (super.noSuchMethod( + Invocation.method(#take, [count]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Stream<_i2.DBusSignal> takeWhile(bool Function(_i2.DBusSignal)? test) => (super.noSuchMethod( - Invocation.method( - #takeWhile, - [test], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); - @override - _i3.Stream<_i2.DBusSignal> skip(int? count) => (super.noSuchMethod( - Invocation.method( - #skip, - [count], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#takeWhile, [test]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + + @override + _i3.Stream<_i2.DBusSignal> skip(int? count) => + (super.noSuchMethod( + Invocation.method(#skip, [count]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Stream<_i2.DBusSignal> skipWhile(bool Function(_i2.DBusSignal)? test) => (super.noSuchMethod( - Invocation.method( - #skipWhile, - [test], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); - @override - _i3.Stream<_i2.DBusSignal> distinct( - [bool Function( - _i2.DBusSignal, - _i2.DBusSignal, - )? equals]) => - (super.noSuchMethod( - Invocation.method( - #distinct, - [equals], - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#skipWhile, [test]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + + @override + _i3.Stream<_i2.DBusSignal> distinct([ + bool Function(_i2.DBusSignal, _i2.DBusSignal)? equals, + ]) => + (super.noSuchMethod( + Invocation.method(#distinct, [equals]), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); + @override _i3.Future<_i2.DBusSignal> firstWhere( bool Function(_i2.DBusSignal)? test, { _i2.DBusSignal Function()? orElse, }) => (super.noSuchMethod( - Invocation.method( - #firstWhere, - [test], - {#orElse: orElse}, - ), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #firstWhere, - [test], - {#orElse: orElse}, - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #firstWhere, - [test], - {#orElse: orElse}, - ), - )), - ) as _i3.Future<_i2.DBusSignal>); + Invocation.method(#firstWhere, [test], {#orElse: orElse}), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#firstWhere, [test], {#orElse: orElse}), + ), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#firstWhere, [test], {#orElse: orElse}), + ), + ), + ) + as _i3.Future<_i2.DBusSignal>); + @override _i3.Future<_i2.DBusSignal> lastWhere( bool Function(_i2.DBusSignal)? test, { _i2.DBusSignal Function()? orElse, }) => (super.noSuchMethod( - Invocation.method( - #lastWhere, - [test], - {#orElse: orElse}, - ), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #lastWhere, - [test], - {#orElse: orElse}, - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #lastWhere, - [test], - {#orElse: orElse}, - ), - )), - ) as _i3.Future<_i2.DBusSignal>); + Invocation.method(#lastWhere, [test], {#orElse: orElse}), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#lastWhere, [test], {#orElse: orElse}), + ), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#lastWhere, [test], {#orElse: orElse}), + ), + ), + ) + as _i3.Future<_i2.DBusSignal>); + @override _i3.Future<_i2.DBusSignal> singleWhere( bool Function(_i2.DBusSignal)? test, { _i2.DBusSignal Function()? orElse, }) => (super.noSuchMethod( - Invocation.method( - #singleWhere, - [test], - {#orElse: orElse}, - ), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #singleWhere, - [test], - {#orElse: orElse}, - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #singleWhere, - [test], - {#orElse: orElse}, - ), - )), - ) as _i3.Future<_i2.DBusSignal>); - @override - _i3.Future<_i2.DBusSignal> elementAt(int? index) => (super.noSuchMethod( - Invocation.method( - #elementAt, - [index], - ), - returnValue: _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #elementAt, - [index], - ), - )), - returnValueForMissingStub: - _i3.Future<_i2.DBusSignal>.value(_FakeDBusSignal_2( - this, - Invocation.method( - #elementAt, - [index], - ), - )), - ) as _i3.Future<_i2.DBusSignal>); + Invocation.method(#singleWhere, [test], {#orElse: orElse}), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#singleWhere, [test], {#orElse: orElse}), + ), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2( + this, + Invocation.method(#singleWhere, [test], {#orElse: orElse}), + ), + ), + ) + as _i3.Future<_i2.DBusSignal>); + + @override + _i3.Future<_i2.DBusSignal> elementAt(int? index) => + (super.noSuchMethod( + Invocation.method(#elementAt, [index]), + returnValue: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.method(#elementAt, [index])), + ), + returnValueForMissingStub: _i3.Future<_i2.DBusSignal>.value( + _FakeDBusSignal_2(this, Invocation.method(#elementAt, [index])), + ), + ) + as _i3.Future<_i2.DBusSignal>); + @override _i3.Stream<_i2.DBusSignal> timeout( Duration? timeLimit, { void Function(_i3.EventSink<_i2.DBusSignal>)? onTimeout, }) => (super.noSuchMethod( - Invocation.method( - #timeout, - [timeLimit], - {#onTimeout: onTimeout}, - ), - returnValue: _i3.Stream<_i2.DBusSignal>.empty(), - returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), - ) as _i3.Stream<_i2.DBusSignal>); + Invocation.method(#timeout, [timeLimit], {#onTimeout: onTimeout}), + returnValue: _i3.Stream<_i2.DBusSignal>.empty(), + returnValueForMissingStub: _i3.Stream<_i2.DBusSignal>.empty(), + ) + as _i3.Stream<_i2.DBusSignal>); } /// A class which mocks [LinuxPlatformInfo]. @@ -753,130 +682,122 @@ class MockDBusRemoteObjectSignalStream extends _i1.Mock /// See the documentation for Mockito's code generation for more information. class MockLinuxPlatformInfo extends _i1.Mock implements _i4.LinuxPlatformInfo { @override - _i3.Future<_i4.LinuxPlatformInfoData> getAll() => (super.noSuchMethod( - Invocation.method( - #getAll, - [], - ), - returnValue: _i3.Future<_i4.LinuxPlatformInfoData>.value( - _FakeLinuxPlatformInfoData_5( - this, - Invocation.method( - #getAll, - [], - ), - )), - returnValueForMissingStub: _i3.Future<_i4.LinuxPlatformInfoData>.value( - _FakeLinuxPlatformInfoData_5( - this, - Invocation.method( - #getAll, - [], - ), - )), - ) as _i3.Future<_i4.LinuxPlatformInfoData>); + _i3.Future<_i4.LinuxPlatformInfoData> getAll() => + (super.noSuchMethod( + Invocation.method(#getAll, []), + returnValue: _i3.Future<_i4.LinuxPlatformInfoData>.value( + _FakeLinuxPlatformInfoData_5( + this, + Invocation.method(#getAll, []), + ), + ), + returnValueForMissingStub: + _i3.Future<_i4.LinuxPlatformInfoData>.value( + _FakeLinuxPlatformInfoData_5( + this, + Invocation.method(#getAll, []), + ), + ), + ) + as _i3.Future<_i4.LinuxPlatformInfoData>); } /// A class which mocks [NotificationStorage]. /// /// See the documentation for Mockito's code generation for more information. class MockNotificationStorage extends _i1.Mock - implements _i6.NotificationStorage { - @override - _i3.Future> getAll() => (super.noSuchMethod( - Invocation.method( - #getAll, - [], - ), - returnValue: _i3.Future>.value( - <_i7.LinuxNotificationInfo>[]), - returnValueForMissingStub: - _i3.Future>.value( - <_i7.LinuxNotificationInfo>[]), - ) as _i3.Future>); - @override - _i3.Future<_i7.LinuxNotificationInfo?> getBySystemId(int? systemId) => - (super.noSuchMethod( - Invocation.method( - #getBySystemId, - [systemId], - ), - returnValue: _i3.Future<_i7.LinuxNotificationInfo?>.value(), - returnValueForMissingStub: - _i3.Future<_i7.LinuxNotificationInfo?>.value(), - ) as _i3.Future<_i7.LinuxNotificationInfo?>); - @override - _i3.Future<_i7.LinuxNotificationInfo?> getById(int? id) => - (super.noSuchMethod( - Invocation.method( - #getById, - [id], - ), - returnValue: _i3.Future<_i7.LinuxNotificationInfo?>.value(), - returnValueForMissingStub: - _i3.Future<_i7.LinuxNotificationInfo?>.value(), - ) as _i3.Future<_i7.LinuxNotificationInfo?>); - @override - _i3.Future insert(_i7.LinuxNotificationInfo? notification) => - (super.noSuchMethod( - Invocation.method( - #insert, - [notification], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future removeById(int? id) => (super.noSuchMethod( - Invocation.method( - #removeById, - [id], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future removeBySystemId(int? systemId) => (super.noSuchMethod( - Invocation.method( - #removeBySystemId, - [systemId], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future removeByIdList(List? idList) => (super.noSuchMethod( - Invocation.method( - #removeByIdList, - [idList], - ), - returnValue: _i3.Future.value(false), - returnValueForMissingStub: _i3.Future.value(false), - ) as _i3.Future); - @override - _i3.Future forceReloadCache() => (super.noSuchMethod( - Invocation.method( - #forceReloadCache, - [], - ), - returnValue: _i3.Future.value(), - returnValueForMissingStub: _i3.Future.value(), - ) as _i3.Future); + implements _i7.NotificationStorage { + @override + _i3.Future> getAll() => + (super.noSuchMethod( + Invocation.method(#getAll, []), + returnValue: _i3.Future>.value( + <_i8.LinuxNotificationInfo>[], + ), + returnValueForMissingStub: + _i3.Future>.value( + <_i8.LinuxNotificationInfo>[], + ), + ) + as _i3.Future>); + + @override + _i3.Future<_i8.LinuxNotificationInfo?> getBySystemId(int? systemId) => + (super.noSuchMethod( + Invocation.method(#getBySystemId, [systemId]), + returnValue: _i3.Future<_i8.LinuxNotificationInfo?>.value(), + returnValueForMissingStub: + _i3.Future<_i8.LinuxNotificationInfo?>.value(), + ) + as _i3.Future<_i8.LinuxNotificationInfo?>); + + @override + _i3.Future<_i8.LinuxNotificationInfo?> getById(int? id) => + (super.noSuchMethod( + Invocation.method(#getById, [id]), + returnValue: _i3.Future<_i8.LinuxNotificationInfo?>.value(), + returnValueForMissingStub: + _i3.Future<_i8.LinuxNotificationInfo?>.value(), + ) + as _i3.Future<_i8.LinuxNotificationInfo?>); + + @override + _i3.Future insert(_i8.LinuxNotificationInfo? notification) => + (super.noSuchMethod( + Invocation.method(#insert, [notification]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future removeById(int? id) => + (super.noSuchMethod( + Invocation.method(#removeById, [id]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future removeBySystemId(int? systemId) => + (super.noSuchMethod( + Invocation.method(#removeBySystemId, [systemId]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future removeByIdList(List? idList) => + (super.noSuchMethod( + Invocation.method(#removeByIdList, [idList]), + returnValue: _i3.Future.value(false), + returnValueForMissingStub: _i3.Future.value(false), + ) + as _i3.Future); + + @override + _i3.Future forceReloadCache() => + (super.noSuchMethod( + Invocation.method(#forceReloadCache, []), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); } /// A class which mocks [DidReceiveNotificationResponseCallback]. /// /// See the documentation for Mockito's code generation for more information. class MockDidReceiveNotificationResponseCallback extends _i1.Mock - implements _i8.DidReceiveNotificationResponseCallback { + implements _i9.DidReceiveNotificationResponseCallback { @override - _i3.Future call(_i9.NotificationResponse? notificationResponse) => + _i3.Future call(_i10.NotificationResponse? notificationResponse) => (super.noSuchMethod( - Invocation.method( - #call, - [notificationResponse], - ), - returnValue: _i3.Future.value(), - returnValueForMissingStub: _i3.Future.value(), - ) as _i3.Future); + Invocation.method(#call, [notificationResponse]), + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) + as _i3.Future); } diff --git a/flutter_local_notifications_linux/test/storage_test.mocks.dart b/flutter_local_notifications_linux/test/storage_test.mocks.dart index d82257e08..865ad66e5 100644 --- a/flutter_local_notifications_linux/test/storage_test.mocks.dart +++ b/flutter_local_notifications_linux/test/storage_test.mocks.dart @@ -1,120 +1,80 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.6 from annotations // in flutter_local_notifications_linux/test/storage_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i4; -import 'dart:convert' as _i6; +import 'dart:convert' as _i7; import 'dart:io' as _i3; -import 'dart:typed_data' as _i7; +import 'dart:typed_data' as _i8; import 'package:flutter_local_notifications_linux/src/file_system.dart' as _i5; import 'package:flutter_local_notifications_linux/src/platform_info.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i6; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: must_be_immutable // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeLinuxPlatformInfoData_0 extends _i1.SmartFake implements _i2.LinuxPlatformInfoData { - _FakeLinuxPlatformInfoData_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeLinuxPlatformInfoData_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeFile_1 extends _i1.SmartFake implements _i3.File { - _FakeFile_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeFile_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeUri_2 extends _i1.SmartFake implements Uri { - _FakeUri_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeUri_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeDirectory_3 extends _i1.SmartFake implements _i3.Directory { - _FakeDirectory_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeDirectory_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeDateTime_4 extends _i1.SmartFake implements DateTime { - _FakeDateTime_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); +class _FakeFileSystemEntity_4 extends _i1.SmartFake + implements _i3.FileSystemEntity { + _FakeFileSystemEntity_4(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeRandomAccessFile_5 extends _i1.SmartFake - implements _i3.RandomAccessFile { - _FakeRandomAccessFile_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); +class _FakeDateTime_5 extends _i1.SmartFake implements DateTime { + _FakeDateTime_5(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeIOSink_6 extends _i1.SmartFake implements _i3.IOSink { - _FakeIOSink_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); +class _FakeRandomAccessFile_6 extends _i1.SmartFake + implements _i3.RandomAccessFile { + _FakeRandomAccessFile_6(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeFileStat_7 extends _i1.SmartFake implements _i3.FileStat { - _FakeFileStat_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); +class _FakeIOSink_7 extends _i1.SmartFake implements _i3.IOSink { + _FakeIOSink_7(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } -class _FakeFileSystemEntity_8 extends _i1.SmartFake - implements _i3.FileSystemEntity { - _FakeFileSystemEntity_8( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); +class _FakeFileStat_8 extends _i1.SmartFake implements _i3.FileStat { + _FakeFileStat_8(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } /// A class which mocks [LinuxPlatformInfo]. @@ -122,28 +82,24 @@ class _FakeFileSystemEntity_8 extends _i1.SmartFake /// See the documentation for Mockito's code generation for more information. class MockLinuxPlatformInfo extends _i1.Mock implements _i2.LinuxPlatformInfo { @override - _i4.Future<_i2.LinuxPlatformInfoData> getAll() => (super.noSuchMethod( - Invocation.method( - #getAll, - [], - ), - returnValue: _i4.Future<_i2.LinuxPlatformInfoData>.value( - _FakeLinuxPlatformInfoData_0( - this, - Invocation.method( - #getAll, - [], - ), - )), - returnValueForMissingStub: _i4.Future<_i2.LinuxPlatformInfoData>.value( - _FakeLinuxPlatformInfoData_0( - this, - Invocation.method( - #getAll, - [], - ), - )), - ) as _i4.Future<_i2.LinuxPlatformInfoData>); + _i4.Future<_i2.LinuxPlatformInfoData> getAll() => + (super.noSuchMethod( + Invocation.method(#getAll, []), + returnValue: _i4.Future<_i2.LinuxPlatformInfoData>.value( + _FakeLinuxPlatformInfoData_0( + this, + Invocation.method(#getAll, []), + ), + ), + returnValueForMissingStub: + _i4.Future<_i2.LinuxPlatformInfoData>.value( + _FakeLinuxPlatformInfoData_0( + this, + Invocation.method(#getAll, []), + ), + ), + ) + as _i4.Future<_i2.LinuxPlatformInfoData>); } /// A class which mocks [FileSystem]. @@ -151,26 +107,16 @@ class MockLinuxPlatformInfo extends _i1.Mock implements _i2.LinuxPlatformInfo { /// See the documentation for Mockito's code generation for more information. class MockFileSystem extends _i1.Mock implements _i5.FileSystem { @override - _i3.File open(String? path) => (super.noSuchMethod( - Invocation.method( - #open, - [path], - ), - returnValue: _FakeFile_1( - this, - Invocation.method( - #open, - [path], - ), - ), - returnValueForMissingStub: _FakeFile_1( - this, - Invocation.method( - #open, - [path], - ), - ), - ) as _i3.File); + _i3.File open(String? path) => + (super.noSuchMethod( + Invocation.method(#open, [path]), + returnValue: _FakeFile_1(this, Invocation.method(#open, [path])), + returnValueForMissingStub: _FakeFile_1( + this, + Invocation.method(#open, [path]), + ), + ) + as _i3.File); } /// A class which mocks [File]. @@ -178,498 +124,440 @@ class MockFileSystem extends _i1.Mock implements _i5.FileSystem { /// See the documentation for Mockito's code generation for more information. class MockFile extends _i1.Mock implements _i3.File { @override - _i3.File get absolute => (super.noSuchMethod( - Invocation.getter(#absolute), - returnValue: _FakeFile_1( - this, - Invocation.getter(#absolute), - ), - returnValueForMissingStub: _FakeFile_1( - this, - Invocation.getter(#absolute), - ), - ) as _i3.File); - @override - String get path => (super.noSuchMethod( - Invocation.getter(#path), - returnValue: '', - returnValueForMissingStub: '', - ) as String); - @override - Uri get uri => (super.noSuchMethod( - Invocation.getter(#uri), - returnValue: _FakeUri_2( - this, - Invocation.getter(#uri), - ), - returnValueForMissingStub: _FakeUri_2( - this, - Invocation.getter(#uri), - ), - ) as Uri); - @override - bool get isAbsolute => (super.noSuchMethod( - Invocation.getter(#isAbsolute), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - _i3.Directory get parent => (super.noSuchMethod( - Invocation.getter(#parent), - returnValue: _FakeDirectory_3( - this, - Invocation.getter(#parent), - ), - returnValueForMissingStub: _FakeDirectory_3( - this, - Invocation.getter(#parent), - ), - ) as _i3.Directory); + _i3.File get absolute => + (super.noSuchMethod( + Invocation.getter(#absolute), + returnValue: _FakeFile_1(this, Invocation.getter(#absolute)), + returnValueForMissingStub: _FakeFile_1( + this, + Invocation.getter(#absolute), + ), + ) + as _i3.File); + + @override + String get path => + (super.noSuchMethod( + Invocation.getter(#path), + returnValue: _i6.dummyValue(this, Invocation.getter(#path)), + returnValueForMissingStub: _i6.dummyValue( + this, + Invocation.getter(#path), + ), + ) + as String); + + @override + Uri get uri => + (super.noSuchMethod( + Invocation.getter(#uri), + returnValue: _FakeUri_2(this, Invocation.getter(#uri)), + returnValueForMissingStub: _FakeUri_2( + this, + Invocation.getter(#uri), + ), + ) + as Uri); + + @override + bool get isAbsolute => + (super.noSuchMethod( + Invocation.getter(#isAbsolute), + returnValue: false, + returnValueForMissingStub: false, + ) + as bool); + + @override + _i3.Directory get parent => + (super.noSuchMethod( + Invocation.getter(#parent), + returnValue: _FakeDirectory_3(this, Invocation.getter(#parent)), + returnValueForMissingStub: _FakeDirectory_3( + this, + Invocation.getter(#parent), + ), + ) + as _i3.Directory); + @override _i4.Future<_i3.File> create({ bool? recursive = false, bool? exclusive = false, }) => (super.noSuchMethod( - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - returnValue: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #create, - [], - { + Invocation.method(#create, [], { #recursive: recursive, #exclusive: exclusive, - }, - ), - )), - returnValueForMissingStub: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #create, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), - )), - ) as _i4.Future<_i3.File>); + }), + returnValue: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method(#create, [], { + #recursive: recursive, + #exclusive: exclusive, + }), + ), + ), + returnValueForMissingStub: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method(#create, [], { + #recursive: recursive, + #exclusive: exclusive, + }), + ), + ), + ) + as _i4.Future<_i3.File>); + @override - void createSync({ - bool? recursive = false, - bool? exclusive = false, - }) => + void createSync({bool? recursive = false, bool? exclusive = false}) => super.noSuchMethod( - Invocation.method( - #createSync, - [], - { - #recursive: recursive, - #exclusive: exclusive, - }, - ), + Invocation.method(#createSync, [], { + #recursive: recursive, + #exclusive: exclusive, + }), returnValueForMissingStub: null, ); + @override - _i4.Future<_i3.File> rename(String? newPath) => (super.noSuchMethod( - Invocation.method( - #rename, - [newPath], - ), - returnValue: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - returnValueForMissingStub: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #rename, - [newPath], - ), - )), - ) as _i4.Future<_i3.File>); - @override - _i3.File renameSync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #renameSync, - [newPath], - ), - returnValue: _FakeFile_1( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_1( - this, - Invocation.method( - #renameSync, - [newPath], - ), - ), - ) as _i3.File); - @override - _i4.Future<_i3.File> copy(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copy, - [newPath], - ), - returnValue: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - returnValueForMissingStub: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #copy, - [newPath], - ), - )), - ) as _i4.Future<_i3.File>); - @override - _i3.File copySync(String? newPath) => (super.noSuchMethod( - Invocation.method( - #copySync, - [newPath], - ), - returnValue: _FakeFile_1( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - returnValueForMissingStub: _FakeFile_1( - this, - Invocation.method( - #copySync, - [newPath], - ), - ), - ) as _i3.File); - @override - _i4.Future length() => (super.noSuchMethod( - Invocation.method( - #length, - [], - ), - returnValue: _i4.Future.value(0), - returnValueForMissingStub: _i4.Future.value(0), - ) as _i4.Future); - @override - int lengthSync() => (super.noSuchMethod( - Invocation.method( - #lengthSync, - [], - ), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - @override - _i4.Future lastAccessed() => (super.noSuchMethod( - Invocation.method( - #lastAccessed, - [], - ), - returnValue: _i4.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - returnValueForMissingStub: _i4.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastAccessed, - [], - ), - )), - ) as _i4.Future); - @override - DateTime lastAccessedSync() => (super.noSuchMethod( - Invocation.method( - #lastAccessedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastAccessedSync, - [], - ), - ), - ) as DateTime); - @override - _i4.Future setLastAccessed(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastAccessed, - [time], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); + _i4.Future<_i3.File> rename(String? newPath) => + (super.noSuchMethod( + Invocation.method(#rename, [newPath]), + returnValue: _i4.Future<_i3.File>.value( + _FakeFile_1(this, Invocation.method(#rename, [newPath])), + ), + returnValueForMissingStub: _i4.Future<_i3.File>.value( + _FakeFile_1(this, Invocation.method(#rename, [newPath])), + ), + ) + as _i4.Future<_i3.File>); + + @override + _i3.File renameSync(String? newPath) => + (super.noSuchMethod( + Invocation.method(#renameSync, [newPath]), + returnValue: _FakeFile_1( + this, + Invocation.method(#renameSync, [newPath]), + ), + returnValueForMissingStub: _FakeFile_1( + this, + Invocation.method(#renameSync, [newPath]), + ), + ) + as _i3.File); + + @override + _i4.Future<_i3.FileSystemEntity> delete({bool? recursive = false}) => + (super.noSuchMethod( + Invocation.method(#delete, [], {#recursive: recursive}), + returnValue: _i4.Future<_i3.FileSystemEntity>.value( + _FakeFileSystemEntity_4( + this, + Invocation.method(#delete, [], {#recursive: recursive}), + ), + ), + returnValueForMissingStub: _i4.Future<_i3.FileSystemEntity>.value( + _FakeFileSystemEntity_4( + this, + Invocation.method(#delete, [], {#recursive: recursive}), + ), + ), + ) + as _i4.Future<_i3.FileSystemEntity>); + + @override + void deleteSync({bool? recursive = false}) => super.noSuchMethod( + Invocation.method(#deleteSync, [], {#recursive: recursive}), + returnValueForMissingStub: null, + ); + + @override + _i4.Future<_i3.File> copy(String? newPath) => + (super.noSuchMethod( + Invocation.method(#copy, [newPath]), + returnValue: _i4.Future<_i3.File>.value( + _FakeFile_1(this, Invocation.method(#copy, [newPath])), + ), + returnValueForMissingStub: _i4.Future<_i3.File>.value( + _FakeFile_1(this, Invocation.method(#copy, [newPath])), + ), + ) + as _i4.Future<_i3.File>); + + @override + _i3.File copySync(String? newPath) => + (super.noSuchMethod( + Invocation.method(#copySync, [newPath]), + returnValue: _FakeFile_1( + this, + Invocation.method(#copySync, [newPath]), + ), + returnValueForMissingStub: _FakeFile_1( + this, + Invocation.method(#copySync, [newPath]), + ), + ) + as _i3.File); + + @override + _i4.Future length() => + (super.noSuchMethod( + Invocation.method(#length, []), + returnValue: _i4.Future.value(0), + returnValueForMissingStub: _i4.Future.value(0), + ) + as _i4.Future); + + @override + int lengthSync() => + (super.noSuchMethod( + Invocation.method(#lengthSync, []), + returnValue: 0, + returnValueForMissingStub: 0, + ) + as int); + + @override + _i4.Future lastAccessed() => + (super.noSuchMethod( + Invocation.method(#lastAccessed, []), + returnValue: _i4.Future.value( + _FakeDateTime_5(this, Invocation.method(#lastAccessed, [])), + ), + returnValueForMissingStub: _i4.Future.value( + _FakeDateTime_5(this, Invocation.method(#lastAccessed, [])), + ), + ) + as _i4.Future); + + @override + DateTime lastAccessedSync() => + (super.noSuchMethod( + Invocation.method(#lastAccessedSync, []), + returnValue: _FakeDateTime_5( + this, + Invocation.method(#lastAccessedSync, []), + ), + returnValueForMissingStub: _FakeDateTime_5( + this, + Invocation.method(#lastAccessedSync, []), + ), + ) + as DateTime); + + @override + _i4.Future setLastAccessed(DateTime? time) => + (super.noSuchMethod( + Invocation.method(#setLastAccessed, [time]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) + as _i4.Future); + @override void setLastAccessedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastAccessedSync, - [time], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#setLastAccessedSync, [time]), + returnValueForMissingStub: null, + ); + @override - _i4.Future lastModified() => (super.noSuchMethod( - Invocation.method( - #lastModified, - [], - ), - returnValue: _i4.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - returnValueForMissingStub: _i4.Future.value(_FakeDateTime_4( - this, - Invocation.method( - #lastModified, - [], - ), - )), - ) as _i4.Future); - @override - DateTime lastModifiedSync() => (super.noSuchMethod( - Invocation.method( - #lastModifiedSync, - [], - ), - returnValue: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - returnValueForMissingStub: _FakeDateTime_4( - this, - Invocation.method( - #lastModifiedSync, - [], - ), - ), - ) as DateTime); - @override - _i4.Future setLastModified(DateTime? time) => (super.noSuchMethod( - Invocation.method( - #setLastModified, - [time], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); + _i4.Future lastModified() => + (super.noSuchMethod( + Invocation.method(#lastModified, []), + returnValue: _i4.Future.value( + _FakeDateTime_5(this, Invocation.method(#lastModified, [])), + ), + returnValueForMissingStub: _i4.Future.value( + _FakeDateTime_5(this, Invocation.method(#lastModified, [])), + ), + ) + as _i4.Future); + + @override + DateTime lastModifiedSync() => + (super.noSuchMethod( + Invocation.method(#lastModifiedSync, []), + returnValue: _FakeDateTime_5( + this, + Invocation.method(#lastModifiedSync, []), + ), + returnValueForMissingStub: _FakeDateTime_5( + this, + Invocation.method(#lastModifiedSync, []), + ), + ) + as DateTime); + + @override + _i4.Future setLastModified(DateTime? time) => + (super.noSuchMethod( + Invocation.method(#setLastModified, [time]), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) + as _i4.Future); + @override void setLastModifiedSync(DateTime? time) => super.noSuchMethod( - Invocation.method( - #setLastModifiedSync, - [time], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#setLastModifiedSync, [time]), + returnValueForMissingStub: null, + ); + @override - _i4.Future<_i3.RandomAccessFile> open( - {_i3.FileMode? mode = _i3.FileMode.read}) => - (super.noSuchMethod( - Invocation.method( - #open, - [], - {#mode: mode}, - ), - returnValue: - _i4.Future<_i3.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - returnValueForMissingStub: - _i4.Future<_i3.RandomAccessFile>.value(_FakeRandomAccessFile_5( - this, - Invocation.method( - #open, - [], - {#mode: mode}, - ), - )), - ) as _i4.Future<_i3.RandomAccessFile>); + _i4.Future<_i3.RandomAccessFile> open({ + _i3.FileMode? mode = _i3.FileMode.read, + }) => + (super.noSuchMethod( + Invocation.method(#open, [], {#mode: mode}), + returnValue: _i4.Future<_i3.RandomAccessFile>.value( + _FakeRandomAccessFile_6( + this, + Invocation.method(#open, [], {#mode: mode}), + ), + ), + returnValueForMissingStub: _i4.Future<_i3.RandomAccessFile>.value( + _FakeRandomAccessFile_6( + this, + Invocation.method(#open, [], {#mode: mode}), + ), + ), + ) + as _i4.Future<_i3.RandomAccessFile>); + @override _i3.RandomAccessFile openSync({_i3.FileMode? mode = _i3.FileMode.read}) => (super.noSuchMethod( - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - returnValue: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - returnValueForMissingStub: _FakeRandomAccessFile_5( - this, - Invocation.method( - #openSync, - [], - {#mode: mode}, - ), - ), - ) as _i3.RandomAccessFile); - @override - _i4.Stream> openRead([ - int? start, - int? end, - ]) => - (super.noSuchMethod( - Invocation.method( - #openRead, - [ - start, - end, - ], - ), - returnValue: _i4.Stream>.empty(), - returnValueForMissingStub: _i4.Stream>.empty(), - ) as _i4.Stream>); + Invocation.method(#openSync, [], {#mode: mode}), + returnValue: _FakeRandomAccessFile_6( + this, + Invocation.method(#openSync, [], {#mode: mode}), + ), + returnValueForMissingStub: _FakeRandomAccessFile_6( + this, + Invocation.method(#openSync, [], {#mode: mode}), + ), + ) + as _i3.RandomAccessFile); + + @override + _i4.Stream> openRead([int? start, int? end]) => + (super.noSuchMethod( + Invocation.method(#openRead, [start, end]), + returnValue: _i4.Stream>.empty(), + returnValueForMissingStub: _i4.Stream>.empty(), + ) + as _i4.Stream>); + @override _i3.IOSink openWrite({ _i3.FileMode? mode = _i3.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), + _i7.Encoding? encoding = const _i7.Utf8Codec(), }) => (super.noSuchMethod( - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - returnValue: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { - #mode: mode, - #encoding: encoding, - }, - ), - ), - returnValueForMissingStub: _FakeIOSink_6( - this, - Invocation.method( - #openWrite, - [], - { + Invocation.method(#openWrite, [], { #mode: mode, #encoding: encoding, - }, - ), - ), - ) as _i3.IOSink); - @override - _i4.Future<_i7.Uint8List> readAsBytes() => (super.noSuchMethod( - Invocation.method( - #readAsBytes, - [], - ), - returnValue: _i4.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - returnValueForMissingStub: - _i4.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - ) as _i4.Future<_i7.Uint8List>); - @override - _i7.Uint8List readAsBytesSync() => (super.noSuchMethod( - Invocation.method( - #readAsBytesSync, - [], - ), - returnValue: _i7.Uint8List(0), - returnValueForMissingStub: _i7.Uint8List(0), - ) as _i7.Uint8List); - @override - _i4.Future readAsString( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsString, - [], - {#encoding: encoding}, - ), - returnValue: _i4.Future.value(''), - returnValueForMissingStub: _i4.Future.value(''), - ) as _i4.Future); - @override - String readAsStringSync({_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsStringSync, - [], - {#encoding: encoding}, - ), - returnValue: '', - returnValueForMissingStub: '', - ) as String); - @override - _i4.Future> readAsLines( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLines, - [], - {#encoding: encoding}, - ), - returnValue: _i4.Future>.value([]), - returnValueForMissingStub: _i4.Future>.value([]), - ) as _i4.Future>); - @override - List readAsLinesSync( - {_i6.Encoding? encoding = const _i6.Utf8Codec()}) => - (super.noSuchMethod( - Invocation.method( - #readAsLinesSync, - [], - {#encoding: encoding}, - ), - returnValue: [], - returnValueForMissingStub: [], - ) as List); + }), + returnValue: _FakeIOSink_7( + this, + Invocation.method(#openWrite, [], { + #mode: mode, + #encoding: encoding, + }), + ), + returnValueForMissingStub: _FakeIOSink_7( + this, + Invocation.method(#openWrite, [], { + #mode: mode, + #encoding: encoding, + }), + ), + ) + as _i3.IOSink); + + @override + _i4.Future<_i8.Uint8List> readAsBytes() => + (super.noSuchMethod( + Invocation.method(#readAsBytes, []), + returnValue: _i4.Future<_i8.Uint8List>.value(_i8.Uint8List(0)), + returnValueForMissingStub: _i4.Future<_i8.Uint8List>.value( + _i8.Uint8List(0), + ), + ) + as _i4.Future<_i8.Uint8List>); + + @override + _i8.Uint8List readAsBytesSync() => + (super.noSuchMethod( + Invocation.method(#readAsBytesSync, []), + returnValue: _i8.Uint8List(0), + returnValueForMissingStub: _i8.Uint8List(0), + ) + as _i8.Uint8List); + + @override + _i4.Future readAsString({ + _i7.Encoding? encoding = const _i7.Utf8Codec(), + }) => + (super.noSuchMethod( + Invocation.method(#readAsString, [], {#encoding: encoding}), + returnValue: _i4.Future.value( + _i6.dummyValue( + this, + Invocation.method(#readAsString, [], {#encoding: encoding}), + ), + ), + returnValueForMissingStub: _i4.Future.value( + _i6.dummyValue( + this, + Invocation.method(#readAsString, [], {#encoding: encoding}), + ), + ), + ) + as _i4.Future); + + @override + String readAsStringSync({_i7.Encoding? encoding = const _i7.Utf8Codec()}) => + (super.noSuchMethod( + Invocation.method(#readAsStringSync, [], {#encoding: encoding}), + returnValue: _i6.dummyValue( + this, + Invocation.method(#readAsStringSync, [], {#encoding: encoding}), + ), + returnValueForMissingStub: _i6.dummyValue( + this, + Invocation.method(#readAsStringSync, [], {#encoding: encoding}), + ), + ) + as String); + + @override + _i4.Future> readAsLines({ + _i7.Encoding? encoding = const _i7.Utf8Codec(), + }) => + (super.noSuchMethod( + Invocation.method(#readAsLines, [], {#encoding: encoding}), + returnValue: _i4.Future>.value([]), + returnValueForMissingStub: _i4.Future>.value( + [], + ), + ) + as _i4.Future>); + + @override + List readAsLinesSync({ + _i7.Encoding? encoding = const _i7.Utf8Codec(), + }) => + (super.noSuchMethod( + Invocation.method(#readAsLinesSync, [], {#encoding: encoding}), + returnValue: [], + returnValueForMissingStub: [], + ) + as List); + @override _i4.Future<_i3.File> writeAsBytes( List? bytes, { @@ -677,245 +565,187 @@ class MockFile extends _i1.Mock implements _i3.File { bool? flush = false, }) => (super.noSuchMethod( - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValue: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #writeAsBytes, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - )), - ) as _i4.Future<_i3.File>); + Invocation.method( + #writeAsBytes, + [bytes], + {#mode: mode, #flush: flush}, + ), + returnValue: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method( + #writeAsBytes, + [bytes], + {#mode: mode, #flush: flush}, + ), + ), + ), + returnValueForMissingStub: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method( + #writeAsBytes, + [bytes], + {#mode: mode, #flush: flush}, + ), + ), + ), + ) + as _i4.Future<_i3.File>); + @override void writeAsBytesSync( List? bytes, { _i3.FileMode? mode = _i3.FileMode.write, bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsBytesSync, - [bytes], - { - #mode: mode, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); + }) => super.noSuchMethod( + Invocation.method(#writeAsBytesSync, [bytes], {#mode: mode, #flush: flush}), + returnValueForMissingStub: null, + ); + @override _i4.Future<_i3.File> writeAsString( String? contents, { _i3.FileMode? mode = _i3.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), + _i7.Encoding? encoding = const _i7.Utf8Codec(), bool? flush = false, }) => (super.noSuchMethod( - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValue: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - returnValueForMissingStub: _i4.Future<_i3.File>.value(_FakeFile_1( - this, - Invocation.method( - #writeAsString, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - )), - ) as _i4.Future<_i3.File>); + Invocation.method( + #writeAsString, + [contents], + {#mode: mode, #encoding: encoding, #flush: flush}, + ), + returnValue: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method( + #writeAsString, + [contents], + {#mode: mode, #encoding: encoding, #flush: flush}, + ), + ), + ), + returnValueForMissingStub: _i4.Future<_i3.File>.value( + _FakeFile_1( + this, + Invocation.method( + #writeAsString, + [contents], + {#mode: mode, #encoding: encoding, #flush: flush}, + ), + ), + ), + ) + as _i4.Future<_i3.File>); + @override void writeAsStringSync( String? contents, { _i3.FileMode? mode = _i3.FileMode.write, - _i6.Encoding? encoding = const _i6.Utf8Codec(), + _i7.Encoding? encoding = const _i7.Utf8Codec(), bool? flush = false, - }) => - super.noSuchMethod( - Invocation.method( - #writeAsStringSync, - [contents], - { - #mode: mode, - #encoding: encoding, - #flush: flush, - }, - ), - returnValueForMissingStub: null, - ); + }) => super.noSuchMethod( + Invocation.method( + #writeAsStringSync, + [contents], + {#mode: mode, #encoding: encoding, #flush: flush}, + ), + returnValueForMissingStub: null, + ); + @override - _i4.Future exists() => (super.noSuchMethod( - Invocation.method( - #exists, - [], - ), - returnValue: _i4.Future.value(false), - returnValueForMissingStub: _i4.Future.value(false), - ) as _i4.Future); - @override - bool existsSync() => (super.noSuchMethod( - Invocation.method( - #existsSync, - [], - ), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - @override - _i4.Future resolveSymbolicLinks() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinks, - [], - ), - returnValue: _i4.Future.value(''), - returnValueForMissingStub: _i4.Future.value(''), - ) as _i4.Future); - @override - String resolveSymbolicLinksSync() => (super.noSuchMethod( - Invocation.method( - #resolveSymbolicLinksSync, - [], - ), - returnValue: '', - returnValueForMissingStub: '', - ) as String); - @override - _i4.Future<_i3.FileStat> stat() => (super.noSuchMethod( - Invocation.method( - #stat, - [], - ), - returnValue: _i4.Future<_i3.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - returnValueForMissingStub: - _i4.Future<_i3.FileStat>.value(_FakeFileStat_7( - this, - Invocation.method( - #stat, - [], - ), - )), - ) as _i4.Future<_i3.FileStat>); - @override - _i3.FileStat statSync() => (super.noSuchMethod( - Invocation.method( - #statSync, - [], - ), - returnValue: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - returnValueForMissingStub: _FakeFileStat_7( - this, - Invocation.method( - #statSync, - [], - ), - ), - ) as _i3.FileStat); + _i4.Future exists() => + (super.noSuchMethod( + Invocation.method(#exists, []), + returnValue: _i4.Future.value(false), + returnValueForMissingStub: _i4.Future.value(false), + ) + as _i4.Future); + @override - _i4.Future<_i3.FileSystemEntity> delete({bool? recursive = false}) => + bool existsSync() => (super.noSuchMethod( - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - returnValue: - _i4.Future<_i3.FileSystemEntity>.value(_FakeFileSystemEntity_8( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - returnValueForMissingStub: - _i4.Future<_i3.FileSystemEntity>.value(_FakeFileSystemEntity_8( - this, - Invocation.method( - #delete, - [], - {#recursive: recursive}, - ), - )), - ) as _i4.Future<_i3.FileSystemEntity>); + Invocation.method(#existsSync, []), + returnValue: false, + returnValueForMissingStub: false, + ) + as bool); + @override - void deleteSync({bool? recursive = false}) => super.noSuchMethod( - Invocation.method( - #deleteSync, - [], - {#recursive: recursive}, - ), - returnValueForMissingStub: null, - ); + _i4.Future resolveSymbolicLinks() => + (super.noSuchMethod( + Invocation.method(#resolveSymbolicLinks, []), + returnValue: _i4.Future.value( + _i6.dummyValue( + this, + Invocation.method(#resolveSymbolicLinks, []), + ), + ), + returnValueForMissingStub: _i4.Future.value( + _i6.dummyValue( + this, + Invocation.method(#resolveSymbolicLinks, []), + ), + ), + ) + as _i4.Future); + + @override + String resolveSymbolicLinksSync() => + (super.noSuchMethod( + Invocation.method(#resolveSymbolicLinksSync, []), + returnValue: _i6.dummyValue( + this, + Invocation.method(#resolveSymbolicLinksSync, []), + ), + returnValueForMissingStub: _i6.dummyValue( + this, + Invocation.method(#resolveSymbolicLinksSync, []), + ), + ) + as String); + + @override + _i4.Future<_i3.FileStat> stat() => + (super.noSuchMethod( + Invocation.method(#stat, []), + returnValue: _i4.Future<_i3.FileStat>.value( + _FakeFileStat_8(this, Invocation.method(#stat, [])), + ), + returnValueForMissingStub: _i4.Future<_i3.FileStat>.value( + _FakeFileStat_8(this, Invocation.method(#stat, [])), + ), + ) + as _i4.Future<_i3.FileStat>); + + @override + _i3.FileStat statSync() => + (super.noSuchMethod( + Invocation.method(#statSync, []), + returnValue: _FakeFileStat_8( + this, + Invocation.method(#statSync, []), + ), + returnValueForMissingStub: _FakeFileStat_8( + this, + Invocation.method(#statSync, []), + ), + ) + as _i3.FileStat); + @override _i4.Stream<_i3.FileSystemEvent> watch({ int? events = 15, bool? recursive = false, }) => (super.noSuchMethod( - Invocation.method( - #watch, - [], - { - #events: events, - #recursive: recursive, - }, - ), - returnValue: _i4.Stream<_i3.FileSystemEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i3.FileSystemEvent>.empty(), - ) as _i4.Stream<_i3.FileSystemEvent>); + Invocation.method(#watch, [], { + #events: events, + #recursive: recursive, + }), + returnValue: _i4.Stream<_i3.FileSystemEvent>.empty(), + returnValueForMissingStub: _i4.Stream<_i3.FileSystemEvent>.empty(), + ) + as _i4.Stream<_i3.FileSystemEvent>); } From 43d24ea5dc7228c26d9aca016009dcac8c19b167 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:18:34 +1100 Subject: [PATCH 7/9] applied formatting changes --- .../flutter_local_notifications_test.dart | 151 +- .../example/lib/configure_in_app_toggle.dart | 83 +- .../example/lib/main.dart | 3678 +++++++++-------- .../example/lib/padded_button.dart | 9 +- .../example/lib/repeating.dart | 295 +- .../example/lib/windows.dart | 330 +- .../lib/src/callback_dispatcher.dart | 60 +- .../flutter_local_notifications_plugin.dart | 316 +- .../lib/src/helpers.dart | 5 +- .../platform_flutter_local_notifications.dart | 458 +- .../src/platform_specifics/android/enums.dart | 8 +- .../platform_specifics/android/message.dart | 8 +- .../android/notification_channel_group.dart | 6 +- .../styles/default_style_information.dart | 5 +- .../darwin/interruption_level.dart | 2 +- .../platform_specifics/darwin/mappers.dart | 118 +- .../darwin/notification_action.dart | 30 +- .../darwin/notification_attachment.dart | 2 +- .../lib/src/typedefs.dart | 4 +- .../lib/src/tz_datetime_mapper.dart | 5 +- ...roid_flutter_local_notifications_test.dart | 2742 ++++++------ .../flutter_local_notifications_test.dart | 20 +- .../ios_flutter_local_notifications_test.dart | 700 ++-- ...acos_flutter_local_notifications_test.dart | 404 +- .../darwin/mappers_test.dart | 31 +- .../lib/src/dbus_wrapper.dart | 29 +- .../lib/src/flutter_local_notifications.dart | 16 +- .../lib/src/helpers.dart | 6 +- .../lib/src/model/capabilities.dart | 30 +- .../lib/src/model/enums.dart | 2 +- .../lib/src/model/hint.dart | 10 +- .../lib/src/model/location.dart | 5 +- .../lib/src/model/notification_details.dart | 5 +- .../lib/src/model/timeout.dart | 2 +- .../lib/src/notification_info.dart | 42 +- .../lib/src/notifications_manager.dart | 187 +- .../lib/src/platform_info.dart | 5 +- .../lib/src/storage.dart | 17 +- .../test/notifications_manager_test.dart | 654 +-- .../test/storage_test.dart | 85 +- ...ocal_notifications_platform_interface.dart | 37 +- .../lib/src/helpers.dart | 14 +- .../lib/src/typedefs.dart | 8 +- .../lib/src/types.dart | 8 +- .../lib/src/details/notification_audio.dart | 18 +- .../lib/src/details/notification_input.dart | 11 +- .../lib/src/details/notification_to_xml.dart | 7 +- .../lib/src/details/xml/audio.dart | 14 +- .../lib/src/details/xml/details.dart | 16 +- .../lib/src/details/xml/header.dart | 16 +- .../lib/src/details/xml/input.dart | 52 +- .../lib/src/details/xml/progress.dart | 22 +- .../lib/src/details/xml/row.dart | 40 +- .../lib/src/details/xml/text.dart | 20 +- .../lib/src/ffi/bindings.dart | 337 +- .../lib/src/ffi/utils.dart | 12 +- .../lib/src/msix/ffi.dart | 5 +- .../lib/src/plugin/base.dart | 6 +- .../lib/src/plugin/ffi.dart | 339 +- .../lib/src/plugin/stub.dart | 7 +- .../test/bindings_test.dart | 86 +- .../test/details_test.dart | 519 +-- .../test/plugin_test.dart | 176 +- .../test/scheduled_test.dart | 55 +- 64 files changed, 6599 insertions(+), 5791 deletions(-) diff --git a/flutter_local_notifications/example/integration_test/flutter_local_notifications_test.dart b/flutter_local_notifications/example/integration_test/flutter_local_notifications_test.dart index a6b83b525..3317884f7 100644 --- a/flutter_local_notifications/example/integration_test/flutter_local_notifications_test.dart +++ b/flutter_local_notifications/example/integration_test/flutter_local_notifications_test.dart @@ -14,14 +14,15 @@ void main() { DarwinInitializationSettings(); final LinuxInitializationSettings initializationSettingsLinux = LinuxInitializationSettings( - defaultActionName: 'Open notification', - defaultIcon: AssetsLinuxIcon('icons/app_icon.png'), - ); + defaultActionName: 'Open notification', + defaultIcon: AssetsLinuxIcon('icons/app_icon.png'), + ); final InitializationSettings initializationSettings = InitializationSettings( - android: initializationSettingsAndroid, - iOS: initializationSettingsIOS, - macOS: initializationSettingsMacOS, - linux: initializationSettingsLinux); + android: initializationSettingsAndroid, + iOS: initializationSettingsIOS, + macOS: initializationSettingsMacOS, + linux: initializationSettingsLinux, + ); late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; group('initialize()', () { setUpAll(() async { @@ -34,31 +35,43 @@ void main() { }); testWidgets( - 'initialize with settings equal to null for the targeting platform ' - 'should throw an ArgumentError', (WidgetTester tester) async { - const InitializationSettings initializationSettings = - InitializationSettings(); - late Matcher errorMessageMatcher; - if (Platform.isAndroid) { - errorMessageMatcher = equals( - 'Android settings must be set when targeting Android platform.'); - } else if (Platform.isIOS) { - errorMessageMatcher = - equals('iOS settings must be set when targeting iOS platform.'); - } else if (Platform.isLinux) { - equals('Linux settings must be set when targeting Linux platform.'); - } else if (Platform.isMacOS) { - errorMessageMatcher = - equals('macOS settings must be set when targeting macOS platform.'); - } else { - errorMessageMatcher = anything; - } - expect( - () async => await flutterLocalNotificationsPlugin - .initialize(initializationSettings), - throwsA(isArgumentError.having( - (ArgumentError e) => e.message, 'message', errorMessageMatcher))); - }); + 'initialize with settings equal to null for the targeting platform ' + 'should throw an ArgumentError', + (WidgetTester tester) async { + const InitializationSettings initializationSettings = + InitializationSettings(); + late Matcher errorMessageMatcher; + if (Platform.isAndroid) { + errorMessageMatcher = equals( + 'Android settings must be set when targeting Android platform.', + ); + } else if (Platform.isIOS) { + errorMessageMatcher = equals( + 'iOS settings must be set when targeting iOS platform.', + ); + } else if (Platform.isLinux) { + equals('Linux settings must be set when targeting Linux platform.'); + } else if (Platform.isMacOS) { + errorMessageMatcher = equals( + 'macOS settings must be set when targeting macOS platform.', + ); + } else { + errorMessageMatcher = anything; + } + expect( + () async => await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ), + throwsA( + isArgumentError.having( + (ArgumentError e) => e.message, + 'message', + errorMessageMatcher, + ), + ), + ); + }, + ); }); group('resolvePlatformSpecificImplementation()', () { setUpAll(() async { @@ -67,57 +80,73 @@ void main() { }); if (Platform.isIOS) { - testWidgets('Can resolve iOS plugin implementation when running on iOS', - (WidgetTester tester) async { + testWidgets('Can resolve iOS plugin implementation when running on iOS', ( + WidgetTester tester, + ) async { expect( - flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>(), - isA()); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin + >(), + isA(), + ); }); } if (Platform.isAndroid) { testWidgets( - 'Can resolve Android plugin implementation when running on Android', - (WidgetTester tester) async { - expect( + 'Can resolve Android plugin implementation when running on Android', + (WidgetTester tester) async { + expect( flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>(), - isA()); - }); + AndroidFlutterLocalNotificationsPlugin + >(), + isA(), + ); + }, + ); } if (Platform.isIOS) { testWidgets( - 'Returns null trying to resolve Android plugin implementation when ' - 'running on iOS', (WidgetTester tester) async { - expect( + 'Returns null trying to resolve Android plugin implementation when ' + 'running on iOS', + (WidgetTester tester) async { + expect( flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>(), - isNull); - }); + AndroidFlutterLocalNotificationsPlugin + >(), + isNull, + ); + }, + ); } if (Platform.isAndroid) { testWidgets( - 'Returns null trying to resolve iOS plugin implementation when ' - 'running on Android', (WidgetTester tester) async { - expect( + 'Returns null trying to resolve iOS plugin implementation when ' + 'running on Android', + (WidgetTester tester) async { + expect( flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>(), - isNull); - }); + IOSFlutterLocalNotificationsPlugin + >(), + isNull, + ); + }, + ); } - testWidgets('Throws argument error requesting base class type', - (WidgetTester tester) async { + testWidgets('Throws argument error requesting base class type', ( + WidgetTester tester, + ) async { expect( - () => flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation(), - throwsArgumentError); + () => flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation(), + throwsArgumentError, + ); }); }); } diff --git a/flutter_local_notifications/example/lib/configure_in_app_toggle.dart b/flutter_local_notifications/example/lib/configure_in_app_toggle.dart index 132f38aff..475ff4c3f 100644 --- a/flutter_local_notifications/example/lib/configure_in_app_toggle.dart +++ b/flutter_local_notifications/example/lib/configure_in_app_toggle.dart @@ -46,48 +46,52 @@ class _ConfigureInAppToggleState extends State { @override Widget build(BuildContext context) => Container( - decoration: BoxDecoration( - color: Colors.grey.shade100, - borderRadius: BorderRadius.circular(8), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Expanded( - child: Padding( - padding: EdgeInsets.fromLTRB(16, 16, 4, 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Show 'Configure in App' context menu option:", - style: TextStyle(fontSize: 14), - ), - SizedBox(height: 8), - Text( - ''' + decoration: BoxDecoration( + color: Colors.grey.shade100, + borderRadius: BorderRadius.circular(8), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Expanded( + child: Padding( + padding: EdgeInsets.fromLTRB(16, 16, 4, 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Show 'Configure in App' context menu option:", + style: TextStyle(fontSize: 14), + ), + SizedBox(height: 8), + Text( + ''' • To access: view a notification on the lock screen, swipe left, and tap 'Options' • Requests 'providesAppNotificationSettings' permission (iOS 12+) • Tap is handled by 'userNotificationCenter(_:openSettingsFor:)' delegate method (not provided by plugin) • Note: Once enabled, this declaration cannot be revoked''', - style: TextStyle(fontSize: 12, color: Colors.black87), - ), - ], + style: TextStyle(fontSize: 12, color: Colors.black87), ), - ), + ], ), - Padding( - padding: const EdgeInsets.only(right: 16), - child: FutureBuilder( - future: widget.flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.checkPermissions(), - builder: (BuildContext context, - AsyncSnapshot snapshot) { + ), + ), + Padding( + padding: const EdgeInsets.only(right: 16), + child: FutureBuilder( + future: widget.flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin + >() + ?.checkPermissions(), + builder: + ( + BuildContext context, + AsyncSnapshot snapshot, + ) { final bool enabled = snapshot.data?.isProvidesAppNotificationSettingsEnabled ?? - false; + false; return Switch( value: enabled, onChanged: !Platform.isIOS || !_isIOS12OrHigher || enabled @@ -96,7 +100,8 @@ class _ConfigureInAppToggleState extends State { final IOSFlutterLocalNotificationsPlugin? plugin = widget.flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>(); + IOSFlutterLocalNotificationsPlugin + >(); if (plugin != null) { await plugin.requestPermissions( alert: true, @@ -109,9 +114,9 @@ class _ConfigureInAppToggleState extends State { }, ); }, - ), - ), - ], + ), ), - ); + ], + ), + ); } diff --git a/flutter_local_notifications/example/lib/main.dart b/flutter_local_notifications/example/lib/main.dart index 011653a2b..49893d9d8 100644 --- a/flutter_local_notifications/example/lib/main.dart +++ b/flutter_local_notifications/example/lib/main.dart @@ -27,8 +27,9 @@ import 'windows.dart' as windows; final StreamController selectNotificationStream = StreamController.broadcast(); -const MethodChannel platform = - MethodChannel('dexterx.dev/flutter_local_notifications_example'); +const MethodChannel platform = MethodChannel( + 'dexterx.dev/flutter_local_notifications_example', +); const String portName = 'notification_send_port'; @@ -65,13 +66,16 @@ const String darwinNotificationCategoryPlain = 'plainCategory'; @pragma('vm:entry-point') void notificationTapBackground(NotificationResponse notificationResponse) { // ignore: avoid_print - print('notification(${notificationResponse.id}) action tapped: ' - '${notificationResponse.actionId} with' - ' payload: ${notificationResponse.payload}'); + print( + 'notification(${notificationResponse.id}) action tapped: ' + '${notificationResponse.actionId} with' + ' payload: ${notificationResponse.payload}', + ); if (notificationResponse.input?.isNotEmpty ?? false) { // ignore: avoid_print print( - 'notification action tapped with input: ${notificationResponse.input}'); + 'notification action tapped with input: ${notificationResponse.input}', + ); } } @@ -91,64 +95,64 @@ Future main() async { final List darwinNotificationCategories = [ - DarwinNotificationCategory( - darwinNotificationCategoryText, - actions: [ - DarwinNotificationAction.text( - 'text_1', - 'Action 1', - buttonTitle: 'Send', - placeholder: 'Placeholder', - ), - ], - ), - DarwinNotificationCategory( - darwinNotificationCategoryPlain, - actions: [ - DarwinNotificationAction.plain('id_1', 'Action 1'), - DarwinNotificationAction.plain( - 'id_2', - 'Action 2 (destructive)', - options: { - DarwinNotificationActionOption.destructive, - }, - ), - DarwinNotificationAction.plain( - navigationActionId, - 'Action 3 (foreground)', - options: { - DarwinNotificationActionOption.foreground, - }, + DarwinNotificationCategory( + darwinNotificationCategoryText, + actions: [ + DarwinNotificationAction.text( + 'text_1', + 'Action 1', + buttonTitle: 'Send', + placeholder: 'Placeholder', + ), + ], ), - DarwinNotificationAction.plain( - 'id_4', - 'Action 4 (auth required)', - options: { - DarwinNotificationActionOption.authenticationRequired, + DarwinNotificationCategory( + darwinNotificationCategoryPlain, + actions: [ + DarwinNotificationAction.plain('id_1', 'Action 1'), + DarwinNotificationAction.plain( + 'id_2', + 'Action 2 (destructive)', + options: { + DarwinNotificationActionOption.destructive, + }, + ), + DarwinNotificationAction.plain( + navigationActionId, + 'Action 3 (foreground)', + options: { + DarwinNotificationActionOption.foreground, + }, + ), + DarwinNotificationAction.plain( + 'id_4', + 'Action 4 (auth required)', + options: { + DarwinNotificationActionOption.authenticationRequired, + }, + ), + ], + options: { + DarwinNotificationCategoryOption.hiddenPreviewShowTitle, }, ), - ], - options: { - DarwinNotificationCategoryOption.hiddenPreviewShowTitle, - }, - ) - ]; + ]; /// Note: permissions aren't requested here just to demonstrate that can be /// done later final DarwinInitializationSettings initializationSettingsDarwin = DarwinInitializationSettings( - requestAlertPermission: false, - requestBadgePermission: false, - requestSoundPermission: false, - notificationCategories: darwinNotificationCategories, - ); + requestAlertPermission: false, + requestBadgePermission: false, + requestSoundPermission: false, + notificationCategories: darwinNotificationCategories, + ); final LinuxInitializationSettings initializationSettingsLinux = LinuxInitializationSettings( - defaultActionName: 'Open notification', - defaultIcon: AssetsLinuxIcon('icons/app_icon.png'), - ); + defaultActionName: 'Open notification', + defaultIcon: AssetsLinuxIcon('icons/app_icon.png'), + ); final InitializationSettings initializationSettings = InitializationSettings( android: initializationSettingsAndroid, @@ -164,8 +168,8 @@ Future main() async { onDidReceiveBackgroundNotificationResponse: notificationTapBackground, ); - final NotificationAppLaunchDetails? notificationAppLaunchDetails = !kIsWeb && - Platform.isLinux + final NotificationAppLaunchDetails? notificationAppLaunchDetails = + !kIsWeb && Platform.isLinux ? null : await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); String initialRoute = HomePage.routeName; @@ -180,7 +184,7 @@ Future main() async { initialRoute: initialRoute, routes: { HomePage.routeName: (_) => HomePage(notificationAppLaunchDetails), - SecondPage.routeName: (_) => SecondPage(selectedNotificationPayload) + SecondPage.routeName: (_) => SecondPage(selectedNotificationPayload), }, ), ); @@ -199,10 +203,8 @@ Future _configureLocalTimeZone() async { } class HomePage extends StatefulWidget { - const HomePage( - this.notificationAppLaunchDetails, { - Key? key, - }) : super(key: key); + const HomePage(this.notificationAppLaunchDetails, {Key? key}) + : super(key: key); static const String routeName = '/'; @@ -230,8 +232,8 @@ class _HomePageState extends State { // Add method channel handler for notification settings const MethodChannel( - 'com.example.flutter_local_notifications_example/settings') - .setMethodCallHandler((MethodCall call) async { + 'com.example.flutter_local_notifications_example/settings', + ).setMethodCallHandler((MethodCall call) async { if (call.method == 'showNotificationSettings') { // Show a simple dialog for demonstration await showDialog( @@ -239,7 +241,8 @@ class _HomePageState extends State { builder: (BuildContext context) => AlertDialog( title: const Text('Notification Settings'), content: const Text( - 'This is a basic example of in-app notification settings UI'), + 'This is a basic example of in-app notification settings UI', + ), actions: [ TextButton( onPressed: () => Navigator.pop(context), @@ -254,9 +257,11 @@ class _HomePageState extends State { Future _isAndroidPermissionGranted() async { if (Platform.isAndroid) { - final bool granted = await flutterLocalNotificationsPlugin + final bool granted = + await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.areNotificationsEnabled() ?? false; @@ -270,27 +275,23 @@ class _HomePageState extends State { if (Platform.isIOS || Platform.isMacOS) { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.requestPermissions( - alert: true, - badge: true, - sound: true, - ); + IOSFlutterLocalNotificationsPlugin + >() + ?.requestPermissions(alert: true, badge: true, sound: true); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() - ?.requestPermissions( - alert: true, - badge: true, - sound: true, - ); + MacOSFlutterLocalNotificationsPlugin + >() + ?.requestPermissions(alert: true, badge: true, sound: true); } else if (Platform.isAndroid) { final AndroidFlutterLocalNotificationsPlugin? androidImplementation = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin + >(); - final bool? grantedNotificationPermission = - await androidImplementation?.requestNotificationsPermission(); + final bool? grantedNotificationPermission = await androidImplementation + ?.requestNotificationsPermission(); setState(() { _notificationsEnabled = grantedNotificationPermission ?? false; }); @@ -301,7 +302,8 @@ class _HomePageState extends State { if (Platform.isIOS || Platform.isMacOS) { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() + IOSFlutterLocalNotificationsPlugin + >() ?.requestPermissions( alert: true, badge: true, @@ -310,7 +312,8 @@ class _HomePageState extends State { ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.requestPermissions( alert: true, badge: true, @@ -322,18 +325,23 @@ class _HomePageState extends State { Future _requestNotificationPolicyAccess() async { final AndroidFlutterLocalNotificationsPlugin? androidImplementation = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin + >(); await androidImplementation?.requestNotificationPolicyAccess(); } void _configureSelectNotificationSubject() { - selectNotificationStream.stream - .listen((NotificationResponse? response) async { - await Navigator.of(context).push(MaterialPageRoute( - builder: (BuildContext context) => - SecondPage(response?.payload, data: response?.data), - )); + selectNotificationStream.stream.listen(( + NotificationResponse? response, + ) async { + await Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => + SecondPage(response?.payload, data: response?.data), + ), + ); }); } @@ -345,551 +353,556 @@ class _HomePageState extends State { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: const Text('Plugin example app'), - ), - body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(8), - child: Center( - child: Column( - children: [ - const Padding( - padding: EdgeInsets.fromLTRB(0, 0, 0, 8), - child: - Text('Tap on a notification when it appears to trigger' - ' navigation'), - ), - _InfoValueString( - title: 'Did notification launch app?', - value: widget.didNotificationLaunchApp, - ), - if (widget.didNotificationLaunchApp) ...[ - const Text('Launch notification details'), - _InfoValueString( - title: 'Notification id', - value: widget.notificationAppLaunchDetails! - .notificationResponse?.id), - _InfoValueString( - title: 'Action id', - value: widget.notificationAppLaunchDetails! - .notificationResponse?.actionId), - _InfoValueString( - title: 'Input', - value: widget.notificationAppLaunchDetails! - .notificationResponse?.input), - _InfoValueString( - title: 'Payload:', - value: widget.notificationAppLaunchDetails! - .notificationResponse?.payload, - ), - ], - PaddedElevatedButton( - buttonText: 'Show plain notification with payload', - onPressed: () async { - await _showNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show plain notification that has no title with ' - 'payload', - onPressed: () async { - await _showNotificationWithNoTitle(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show plain notification that has no body with ' - 'payload', - onPressed: () async { - await _showNotificationWithNoBody(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with custom sound', - onPressed: () async { - await _showNotificationCustomSound(); - }, - ), - if (kIsWeb || !Platform.isLinux) ...[ - PaddedElevatedButton( - buttonText: - 'Schedule notification to appear in 5 seconds ' - 'based on local time zone', - onPressed: () async { - await _zonedScheduleNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Schedule notification to appear in 5 seconds ' - 'based on local time zone using alarm clock', - onPressed: () async { - await _zonedScheduleAlarmClockNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Check pending notifications', - onPressed: () async { - await _checkPendingNotificationRequests(); - }, - ), - PaddedElevatedButton( - buttonText: 'Get active notifications', - onPressed: () async { - await _getActiveNotifications(); - }, - ), - ], - PaddedElevatedButton( - buttonText: 'Show notification from silent channel', - onPressed: () async { - await _showNotificationWithNoSound(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show silent notification from channel with sound', - onPressed: () async { - await _showNotificationSilently(); - }, - ), - PaddedElevatedButton( - buttonText: 'Cancel latest notification', - onPressed: () async { - await _cancelNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Cancel all notifications', - onPressed: () async { - await _cancelAllNotifications(); - }, - ), - if (Platform.isAndroid || Platform.isIOS || Platform.isMacOS) - PaddedElevatedButton( - buttonText: 'Cancel all pending notifications', - onPressed: () async { - await _cancelAllPendingNotifications(); - }, - ), - if (!Platform.isWindows) ...repeating.examples(context), - const Divider(), - const Text( - 'Notifications with actions', - style: TextStyle(fontWeight: FontWeight.bold), - ), - PaddedElevatedButton( - buttonText: 'Show notification with plain actions', - onPressed: () async { - await _showNotificationWithActions(); - }, - ), - if (Platform.isLinux) - PaddedElevatedButton( - buttonText: - 'Show notification with icon action (if supported)', - onPressed: () async { - await _showNotificationWithIconAction(); - }, - ), - if (!Platform.isLinux) - PaddedElevatedButton( - buttonText: 'Show notification with text action', - onPressed: () async { - await _showNotificationWithTextAction(); - }, - ), - if (!Platform.isLinux) - PaddedElevatedButton( - buttonText: 'Show notification with text choice', - onPressed: () async { - await _showNotificationWithTextChoice(); - }, - ), - const Divider(), - if (Platform.isAndroid) ...[ - const Text( - 'Android-specific examples', - style: TextStyle(fontWeight: FontWeight.bold), - ), - Text('notifications enabled: $_notificationsEnabled'), - PaddedElevatedButton( - buttonText: - 'Check if notifications are enabled for this app', - onPressed: _areNotifcationsEnabledOnAndroid, - ), - PaddedElevatedButton( - buttonText: 'Request permission (API 33+)', - onPressed: () => _requestPermissions(), - ), - PaddedElevatedButton( - buttonText: 'Request notification policy access', - onPressed: () => _requestNotificationPolicyAccess(), - ), - PaddedElevatedButton( - buttonText: - 'Show plain notification with payload and update ' - 'channel description', - onPressed: () async { - await _showNotificationUpdateChannelDescription(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show plain notification as public on every ' - 'lockscreen', - onPressed: () async { - await _showPublicNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with custom vibration pattern, ' - 'red LED and red icon', - onPressed: () async { - await _showNotificationCustomVibrationIconLed(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification using Android Uri sound', - onPressed: () async { - await _showSoundUriNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification that times out after 3 seconds', - onPressed: () async { - await _showTimeoutNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show insistent notification', - onPressed: () async { - await _showInsistentNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show big picture notification using local images', - onPressed: () async { - await _showBigPictureNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show big picture notification using base64 String ' - 'for images', - onPressed: () async { - await _showBigPictureNotificationBase64(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show big picture notification using URLs for ' - 'Images', - onPressed: () async { - await _showBigPictureNotificationURL(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show big picture notification, hide large icon ' - 'on expand', - onPressed: () async { - await _showBigPictureNotificationHiddenLargeIcon(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show media notification', - onPressed: () async { - await _showNotificationMediaStyle(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show big text notification', - onPressed: () async { - await _showBigTextNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show inbox notification', - onPressed: () async { - await _showInboxNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show messaging notification', - onPressed: () async { - await _showMessagingNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show grouped notifications', - onPressed: () async { - await _showGroupedNotifications(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with tag', - onPressed: () async { - await _showNotificationWithTag(); - }, - ), - PaddedElevatedButton( - buttonText: 'Cancel notification with tag', - onPressed: () async { - await _cancelNotificationWithTag(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show ongoing notification', - onPressed: () async { - await _showOngoingNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with no badge, alert only once', - onPressed: () async { - await _showNotificationWithNoBadge(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show progress notification - updates every second', - onPressed: () async { - await _showProgressNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show indeterminate progress notification', - onPressed: () async { - await _showIndeterminateProgressNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification without timestamp', - onPressed: () async { - await _showNotificationWithoutTimestamp(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with custom timestamp', - onPressed: () async { - await _showNotificationWithCustomTimestamp(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with custom sub-text', - onPressed: () async { - await _showNotificationWithCustomSubText(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with chronometer', - onPressed: () async { - await _showNotificationWithChronometer(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Request full-screen intent permission (API 34+)', - onPressed: () async { - await _requestFullScreenIntentPermission(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show full-screen notification', - onPressed: () async { - await _showFullScreenNotification(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with number if the launcher ' - 'supports', - onPressed: () async { - await _showNotificationWithNumber(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with sound controlled by ' - 'alarm volume', - onPressed: () async { - await _showNotificationWithAudioAttributeAlarm(); - }, - ), - PaddedElevatedButton( - buttonText: 'Create grouped notification channels', - onPressed: () async { - await _createNotificationChannelGroup(); - }, - ), - PaddedElevatedButton( - buttonText: 'Delete notification channel group', - onPressed: () async { - await _deleteNotificationChannelGroup(); - }, - ), - PaddedElevatedButton( - buttonText: 'Create notification channel', - onPressed: () async { - await _createNotificationChannel(); - }, - ), - PaddedElevatedButton( - buttonText: 'Delete notification channel', - onPressed: () async { - await _deleteNotificationChannel(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Create notification channel that ignores dnd', - onPressed: () async { - await _createNotificationChannelWithDndBypass(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification that ignores dnd', - onPressed: () async { - await _showNotificationWithDndBypass(); - }, - ), - PaddedElevatedButton( - buttonText: 'Get notification channels', - onPressed: () async { - await _getNotificationChannels(); - }, - ), - PaddedElevatedButton( - buttonText: 'Start foreground service', - onPressed: () async { - await _startForegroundService(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Start foreground service with blue background ' - 'notification', - onPressed: () async { - await _startForegroundServiceWithBlueBackgroundNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Stop foreground service', - onPressed: () async { - await _stopForegroundService(); - }, - ), - ], - if (!kIsWeb && - (Platform.isIOS || Platform.isMacOS)) ...[ - const Text( - 'iOS and macOS-specific examples', - style: TextStyle(fontWeight: FontWeight.bold), - ), - PaddedElevatedButton( - buttonText: 'Check permissions', - onPressed: _checkNotificationsOnCupertino, - ), - PaddedElevatedButton( - buttonText: 'Request permission', - onPressed: _requestPermissions, - ), - PaddedElevatedButton( - buttonText: - 'Request permission with critical alert permission', - onPressed: _requestPermissionsWithCriticalAlert, - ), - PaddedElevatedButton( - buttonText: 'Show notification with subtitle', - onPressed: () async { - await _showNotificationWithSubtitle(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with critical sound', - onPressed: () async { - await _showNotificationWithCriticalSound(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with icon badge', - onPressed: () async { - await _showNotificationWithIconBadge(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with attachment (with thumbnail)', - onPressed: () async { - await _showNotificationWithAttachment( - hideThumbnail: false); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with attachment (no thumbnail)', - onPressed: () async { - await _showNotificationWithAttachment( - hideThumbnail: true); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with attachment (clipped thumbnail)', - onPressed: () async { - await _showNotificationWithClippedThumbnailAttachment(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with thread identifier', - onPressed: () async { - await _showNotificationsWithThreadIdentifier(); - }, - ), - PaddedElevatedButton( - buttonText: - 'Show notification with time sensitive interruption ' - 'level', - onPressed: () async { - 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 (Platform.isIOS) ...[ - ConfigureInAppToggle( - flutterLocalNotificationsPlugin: - flutterLocalNotificationsPlugin, - ), - const SizedBox( - height: 50, - ), - ], - ], - if (!kIsWeb && Platform.isLinux) ...[ - const Text( - 'Linux-specific examples', - style: TextStyle(fontWeight: FontWeight.bold), - ), - FutureBuilder( - future: getLinuxCapabilities(), - builder: ( + appBar: AppBar(title: const Text('Plugin example app')), + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(8), + child: Center( + child: Column( + children: [ + const Padding( + padding: EdgeInsets.fromLTRB(0, 0, 0, 8), + child: Text( + 'Tap on a notification when it appears to trigger' + ' navigation', + ), + ), + _InfoValueString( + title: 'Did notification launch app?', + value: widget.didNotificationLaunchApp, + ), + if (widget.didNotificationLaunchApp) ...[ + const Text('Launch notification details'), + _InfoValueString( + title: 'Notification id', + value: widget + .notificationAppLaunchDetails! + .notificationResponse + ?.id, + ), + _InfoValueString( + title: 'Action id', + value: widget + .notificationAppLaunchDetails! + .notificationResponse + ?.actionId, + ), + _InfoValueString( + title: 'Input', + value: widget + .notificationAppLaunchDetails! + .notificationResponse + ?.input, + ), + _InfoValueString( + title: 'Payload:', + value: widget + .notificationAppLaunchDetails! + .notificationResponse + ?.payload, + ), + ], + PaddedElevatedButton( + buttonText: 'Show plain notification with payload', + onPressed: () async { + await _showNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show plain notification that has no title with ' + 'payload', + onPressed: () async { + await _showNotificationWithNoTitle(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show plain notification that has no body with ' + 'payload', + onPressed: () async { + await _showNotificationWithNoBody(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with custom sound', + onPressed: () async { + await _showNotificationCustomSound(); + }, + ), + if (kIsWeb || !Platform.isLinux) ...[ + PaddedElevatedButton( + buttonText: + 'Schedule notification to appear in 5 seconds ' + 'based on local time zone', + onPressed: () async { + await _zonedScheduleNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule notification to appear in 5 seconds ' + 'based on local time zone using alarm clock', + onPressed: () async { + await _zonedScheduleAlarmClockNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Check pending notifications', + onPressed: () async { + await _checkPendingNotificationRequests(); + }, + ), + PaddedElevatedButton( + buttonText: 'Get active notifications', + onPressed: () async { + await _getActiveNotifications(); + }, + ), + ], + PaddedElevatedButton( + buttonText: 'Show notification from silent channel', + onPressed: () async { + await _showNotificationWithNoSound(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show silent notification from channel with sound', + onPressed: () async { + await _showNotificationSilently(); + }, + ), + PaddedElevatedButton( + buttonText: 'Cancel latest notification', + onPressed: () async { + await _cancelNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Cancel all notifications', + onPressed: () async { + await _cancelAllNotifications(); + }, + ), + if (Platform.isAndroid || Platform.isIOS || Platform.isMacOS) + PaddedElevatedButton( + buttonText: 'Cancel all pending notifications', + onPressed: () async { + await _cancelAllPendingNotifications(); + }, + ), + if (!Platform.isWindows) ...repeating.examples(context), + const Divider(), + const Text( + 'Notifications with actions', + style: TextStyle(fontWeight: FontWeight.bold), + ), + PaddedElevatedButton( + buttonText: 'Show notification with plain actions', + onPressed: () async { + await _showNotificationWithActions(); + }, + ), + if (Platform.isLinux) + PaddedElevatedButton( + buttonText: + 'Show notification with icon action (if supported)', + onPressed: () async { + await _showNotificationWithIconAction(); + }, + ), + if (!Platform.isLinux) + PaddedElevatedButton( + buttonText: 'Show notification with text action', + onPressed: () async { + await _showNotificationWithTextAction(); + }, + ), + if (!Platform.isLinux) + PaddedElevatedButton( + buttonText: 'Show notification with text choice', + onPressed: () async { + await _showNotificationWithTextChoice(); + }, + ), + const Divider(), + if (Platform.isAndroid) ...[ + const Text( + 'Android-specific examples', + style: TextStyle(fontWeight: FontWeight.bold), + ), + Text('notifications enabled: $_notificationsEnabled'), + PaddedElevatedButton( + buttonText: 'Check if notifications are enabled for this app', + onPressed: _areNotifcationsEnabledOnAndroid, + ), + PaddedElevatedButton( + buttonText: 'Request permission (API 33+)', + onPressed: () => _requestPermissions(), + ), + PaddedElevatedButton( + buttonText: 'Request notification policy access', + onPressed: () => _requestNotificationPolicyAccess(), + ), + PaddedElevatedButton( + buttonText: + 'Show plain notification with payload and update ' + 'channel description', + onPressed: () async { + await _showNotificationUpdateChannelDescription(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show plain notification as public on every ' + 'lockscreen', + onPressed: () async { + await _showPublicNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with custom vibration pattern, ' + 'red LED and red icon', + onPressed: () async { + await _showNotificationCustomVibrationIconLed(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification using Android Uri sound', + onPressed: () async { + await _showSoundUriNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification that times out after 3 seconds', + onPressed: () async { + await _showTimeoutNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show insistent notification', + onPressed: () async { + await _showInsistentNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show big picture notification using local images', + onPressed: () async { + await _showBigPictureNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show big picture notification using base64 String ' + 'for images', + onPressed: () async { + await _showBigPictureNotificationBase64(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show big picture notification using URLs for ' + 'Images', + onPressed: () async { + await _showBigPictureNotificationURL(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show big picture notification, hide large icon ' + 'on expand', + onPressed: () async { + await _showBigPictureNotificationHiddenLargeIcon(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show media notification', + onPressed: () async { + await _showNotificationMediaStyle(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show big text notification', + onPressed: () async { + await _showBigTextNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show inbox notification', + onPressed: () async { + await _showInboxNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show messaging notification', + onPressed: () async { + await _showMessagingNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show grouped notifications', + onPressed: () async { + await _showGroupedNotifications(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with tag', + onPressed: () async { + await _showNotificationWithTag(); + }, + ), + PaddedElevatedButton( + buttonText: 'Cancel notification with tag', + onPressed: () async { + await _cancelNotificationWithTag(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show ongoing notification', + onPressed: () async { + await _showOngoingNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with no badge, alert only once', + onPressed: () async { + await _showNotificationWithNoBadge(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show progress notification - updates every second', + onPressed: () async { + await _showProgressNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show indeterminate progress notification', + onPressed: () async { + await _showIndeterminateProgressNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification without timestamp', + onPressed: () async { + await _showNotificationWithoutTimestamp(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with custom timestamp', + onPressed: () async { + await _showNotificationWithCustomTimestamp(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with custom sub-text', + onPressed: () async { + await _showNotificationWithCustomSubText(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with chronometer', + onPressed: () async { + await _showNotificationWithChronometer(); + }, + ), + PaddedElevatedButton( + buttonText: 'Request full-screen intent permission (API 34+)', + onPressed: () async { + await _requestFullScreenIntentPermission(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show full-screen notification', + onPressed: () async { + await _showFullScreenNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with number if the launcher ' + 'supports', + onPressed: () async { + await _showNotificationWithNumber(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with sound controlled by ' + 'alarm volume', + onPressed: () async { + await _showNotificationWithAudioAttributeAlarm(); + }, + ), + PaddedElevatedButton( + buttonText: 'Create grouped notification channels', + onPressed: () async { + await _createNotificationChannelGroup(); + }, + ), + PaddedElevatedButton( + buttonText: 'Delete notification channel group', + onPressed: () async { + await _deleteNotificationChannelGroup(); + }, + ), + PaddedElevatedButton( + buttonText: 'Create notification channel', + onPressed: () async { + await _createNotificationChannel(); + }, + ), + PaddedElevatedButton( + buttonText: 'Delete notification channel', + onPressed: () async { + await _deleteNotificationChannel(); + }, + ), + PaddedElevatedButton( + buttonText: 'Create notification channel that ignores dnd', + onPressed: () async { + await _createNotificationChannelWithDndBypass(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification that ignores dnd', + onPressed: () async { + await _showNotificationWithDndBypass(); + }, + ), + PaddedElevatedButton( + buttonText: 'Get notification channels', + onPressed: () async { + await _getNotificationChannels(); + }, + ), + PaddedElevatedButton( + buttonText: 'Start foreground service', + onPressed: () async { + await _startForegroundService(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Start foreground service with blue background ' + 'notification', + onPressed: () async { + await _startForegroundServiceWithBlueBackgroundNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Stop foreground service', + onPressed: () async { + await _stopForegroundService(); + }, + ), + ], + if (!kIsWeb && (Platform.isIOS || Platform.isMacOS)) ...[ + const Text( + 'iOS and macOS-specific examples', + style: TextStyle(fontWeight: FontWeight.bold), + ), + PaddedElevatedButton( + buttonText: 'Check permissions', + onPressed: _checkNotificationsOnCupertino, + ), + PaddedElevatedButton( + buttonText: 'Request permission', + onPressed: _requestPermissions, + ), + PaddedElevatedButton( + buttonText: + 'Request permission with critical alert permission', + onPressed: _requestPermissionsWithCriticalAlert, + ), + PaddedElevatedButton( + buttonText: 'Show notification with subtitle', + onPressed: () async { + await _showNotificationWithSubtitle(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with critical sound', + onPressed: () async { + await _showNotificationWithCriticalSound(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with icon badge', + onPressed: () async { + await _showNotificationWithIconBadge(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with attachment (with thumbnail)', + onPressed: () async { + await _showNotificationWithAttachment(hideThumbnail: false); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with attachment (no thumbnail)', + onPressed: () async { + await _showNotificationWithAttachment(hideThumbnail: true); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with attachment (clipped thumbnail)', + onPressed: () async { + await _showNotificationWithClippedThumbnailAttachment(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with thread identifier', + onPressed: () async { + await _showNotificationsWithThreadIdentifier(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification with time sensitive interruption ' + 'level', + onPressed: () async { + 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 (Platform.isIOS) ...[ + ConfigureInAppToggle( + flutterLocalNotificationsPlugin: + flutterLocalNotificationsPlugin, + ), + const SizedBox(height: 50), + ], + ], + if (!kIsWeb && Platform.isLinux) ...[ + const Text( + 'Linux-specific examples', + style: TextStyle(fontWeight: FontWeight.bold), + ), + FutureBuilder( + future: getLinuxCapabilities(), + builder: + ( BuildContext context, AsyncSnapshot snapshot, ) { @@ -959,133 +972,140 @@ class _HomePageState extends State { return const CircularProgressIndicator(); } }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with body markup', - onPressed: () async { - await _showLinuxNotificationWithBodyMarkup(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with category', - onPressed: () async { - await _showLinuxNotificationWithCategory(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with byte data icon', - onPressed: () async { - await _showLinuxNotificationWithByteDataIcon(); - }, - ), - Builder( - builder: (BuildContext context) => PaddedElevatedButton( - buttonText: 'Show notification with file path icon', - onPressed: () async { - final String path = _linuxIconPathController.text; - if (path.isEmpty) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Please enter the icon path'), - ), - ); - return; - } - await _showLinuxNotificationWithPathIcon(path); - }, - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), - child: TextField( - controller: _linuxIconPathController, - decoration: InputDecoration( - hintText: 'Enter the icon path', - constraints: const BoxConstraints.tightFor( - width: 300, - ), - suffixIcon: IconButton( - icon: const Icon(Icons.clear), - onPressed: () => _linuxIconPathController.clear(), + ), + PaddedElevatedButton( + buttonText: 'Show notification with body markup', + onPressed: () async { + await _showLinuxNotificationWithBodyMarkup(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with category', + onPressed: () async { + await _showLinuxNotificationWithCategory(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with byte data icon', + onPressed: () async { + await _showLinuxNotificationWithByteDataIcon(); + }, + ), + Builder( + builder: (BuildContext context) => PaddedElevatedButton( + buttonText: 'Show notification with file path icon', + onPressed: () async { + final String path = _linuxIconPathController.text; + if (path.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Please enter the icon path'), ), - ), + ); + return; + } + await _showLinuxNotificationWithPathIcon(path); + }, + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), + child: TextField( + controller: _linuxIconPathController, + decoration: InputDecoration( + hintText: 'Enter the icon path', + constraints: const BoxConstraints.tightFor(width: 300), + suffixIcon: IconButton( + icon: const Icon(Icons.clear), + onPressed: () => _linuxIconPathController.clear(), ), ), - PaddedElevatedButton( - buttonText: 'Show notification with theme icon', - onPressed: () async { - await _showLinuxNotificationWithThemeIcon(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with theme sound', - onPressed: () async { - await _showLinuxNotificationWithThemeSound(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with critical urgency', - onPressed: () async { - await _showLinuxNotificationWithCriticalUrgency(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with timeout', - onPressed: () async { - await _showLinuxNotificationWithTimeout(); - }, - ), - PaddedElevatedButton( - buttonText: 'Suppress notification sound', - onPressed: () async { - await _showLinuxNotificationSuppressSound(); - }, - ), - PaddedElevatedButton( - buttonText: 'Transient notification', - onPressed: () async { - await _showLinuxNotificationTransient(); - }, - ), - PaddedElevatedButton( - buttonText: 'Resident notification', - onPressed: () async { - await _showLinuxNotificationResident(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification on ' - 'different screen location', - onPressed: () async { - await _showLinuxNotificationDifferentLocation(); - }, - ), - ], - if (!kIsWeb && Platform.isWindows) ...windows.examples(), - ], - ), - ), + ), + ), + PaddedElevatedButton( + buttonText: 'Show notification with theme icon', + onPressed: () async { + await _showLinuxNotificationWithThemeIcon(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with theme sound', + onPressed: () async { + await _showLinuxNotificationWithThemeSound(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with critical urgency', + onPressed: () async { + await _showLinuxNotificationWithCriticalUrgency(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with timeout', + onPressed: () async { + await _showLinuxNotificationWithTimeout(); + }, + ), + PaddedElevatedButton( + buttonText: 'Suppress notification sound', + onPressed: () async { + await _showLinuxNotificationSuppressSound(); + }, + ), + PaddedElevatedButton( + buttonText: 'Transient notification', + onPressed: () async { + await _showLinuxNotificationTransient(); + }, + ), + PaddedElevatedButton( + buttonText: 'Resident notification', + onPressed: () async { + await _showLinuxNotificationResident(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Show notification on ' + 'different screen location', + onPressed: () async { + await _showLinuxNotificationDifferentLocation(); + }, + ), + ], + if (!kIsWeb && Platform.isWindows) ...windows.examples(), + ], ), ), - ); + ), + ), + ); Future _showNotification() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker'); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithActions() async { - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( + const AndroidNotificationDetails + androidNotificationDetails = AndroidNotificationDetails( 'your channel id', 'your channel name', channelDescription: 'your channel description', @@ -1114,55 +1134,50 @@ class _HomePageState extends State { // user tapped on a action (this mimics the behavior on iOS). cancelNotification: false, ), - AndroidNotificationAction('read', 'Mark as read', - semanticAction: SemanticAction.markAsRead, invisible: true), + AndroidNotificationAction( + 'read', + 'Mark as read', + semanticAction: SemanticAction.markAsRead, + invisible: true, + ), ], ); const DarwinNotificationDetails iosNotificationDetails = DarwinNotificationDetails( - categoryIdentifier: darwinNotificationCategoryPlain, - ); + categoryIdentifier: darwinNotificationCategoryPlain, + ); const DarwinNotificationDetails macOSNotificationDetails = DarwinNotificationDetails( - categoryIdentifier: darwinNotificationCategoryPlain, - ); + categoryIdentifier: darwinNotificationCategoryPlain, + ); const LinuxNotificationDetails linuxNotificationDetails = LinuxNotificationDetails( - actions: [ - LinuxNotificationAction( - key: urlLaunchActionId, - label: 'Action 1', - ), - LinuxNotificationAction( - key: navigationActionId, - label: 'Action 2', - ), - ], - ); + actions: [ + LinuxNotificationAction(key: urlLaunchActionId, label: 'Action 1'), + LinuxNotificationAction(key: navigationActionId, label: 'Action 2'), + ], + ); final WindowsNotificationDetails windowsNotificationsDetails = WindowsNotificationDetails( - subtitle: 'Click the three dots for another button', - actions: [ - const WindowsAction( - content: 'Text', - arguments: 'text', - ), - WindowsAction( - content: 'Image', - arguments: 'image', - imageUri: WindowsImage.getAssetUri('icons/coworker.png'), - ), - const WindowsAction( - content: 'Context', - arguments: 'context', - placement: WindowsActionPlacement.contextMenu, - ), - ], - ); + subtitle: 'Click the three dots for another button', + actions: [ + const WindowsAction(content: 'Text', arguments: 'text'), + WindowsAction( + content: 'Image', + arguments: 'image', + imageUri: WindowsImage.getAssetUri('icons/coworker.png'), + ), + const WindowsAction( + content: 'Context', + arguments: 'context', + placement: WindowsActionPlacement.contextMenu, + ), + ], + ); final NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, @@ -1172,50 +1187,58 @@ class _HomePageState extends State { windows: windowsNotificationsDetails, ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item z'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item z', + ); } Future _showNotificationWithTextAction() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - actions: [ - AndroidNotificationAction( - 'text_id_1', - 'Enter Text', - icon: DrawableResourceAndroidBitmap('food'), - inputs: [ - AndroidNotificationActionInput( - label: 'Enter a message', + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + actions: [ + AndroidNotificationAction( + 'text_id_1', + 'Enter Text', + icon: DrawableResourceAndroidBitmap('food'), + inputs: [ + AndroidNotificationActionInput(label: 'Enter a message'), + ], + semanticAction: SemanticAction.reply, ), ], - semanticAction: SemanticAction.reply, - ), - ], - ); + ); const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - categoryIdentifier: darwinNotificationCategoryText, - ); + categoryIdentifier: darwinNotificationCategoryText, + ); const WindowsNotificationDetails windowsNotificationDetails = WindowsNotificationDetails( - actions: [ - WindowsAction( - content: 'Send', arguments: 'send-reply', inputId: 'text'), - ], - inputs: [ - WindowsTextInput( - id: 'text', title: 'Send a reply?', placeHolderContent: 'Message'), - ], - ); + actions: [ + WindowsAction( + content: 'Send', + arguments: 'send-reply', + inputId: 'text', + ), + ], + inputs: [ + WindowsTextInput( + id: 'text', + title: 'Send a reply?', + placeHolderContent: 'Message', + ), + ], + ); const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, @@ -1224,77 +1247,85 @@ class _HomePageState extends State { windows: windowsNotificationDetails, ); - await flutterLocalNotificationsPlugin.show(id++, 'Text Input Notification', - 'Expand to see input action', notificationDetails, - payload: 'item x'); + await flutterLocalNotificationsPlugin.show( + id++, + 'Text Input Notification', + 'Expand to see input action', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithIconAction() async { const LinuxNotificationDetails linuxNotificationDetails = LinuxNotificationDetails( - actions: [ - LinuxNotificationAction( - key: 'media-eject', - label: 'Eject', - ), - ], - ); + actions: [ + LinuxNotificationAction(key: 'media-eject', label: 'Eject'), + ], + ); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxNotificationDetails, ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item z'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item z', + ); } Future _showNotificationWithTextChoice() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - actions: [ - AndroidNotificationAction( - 'text_id_2', - 'Action 2', - icon: DrawableResourceAndroidBitmap('food'), - inputs: [ - AndroidNotificationActionInput( - choices: ['ABC', 'DEF'], - allowFreeFormInput: false, + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + actions: [ + AndroidNotificationAction( + 'text_id_2', + 'Action 2', + icon: DrawableResourceAndroidBitmap('food'), + inputs: [ + AndroidNotificationActionInput( + choices: ['ABC', 'DEF'], + allowFreeFormInput: false, + ), + ], + contextual: true, ), ], - contextual: true, - ), - ], - ); + ); const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - categoryIdentifier: darwinNotificationCategoryText, - ); + categoryIdentifier: darwinNotificationCategoryText, + ); const WindowsNotificationDetails windowsNotificationDetails = WindowsNotificationDetails( - actions: [ - WindowsAction( - content: 'Submit', arguments: 'submit', inputId: 'choice'), - ], - inputs: [ - WindowsSelectionInput( - id: 'choice', - defaultItem: 'abc', - items: [ - WindowsSelection(id: 'abc', content: 'abc'), - WindowsSelection(id: 'def', content: 'def'), + actions: [ + WindowsAction( + content: 'Submit', + arguments: 'submit', + inputId: 'choice', + ), ], - ), - ], - ); + inputs: [ + WindowsSelectionInput( + id: 'choice', + defaultItem: 'abc', + items: [ + WindowsSelection(id: 'abc', content: 'abc'), + WindowsSelection(id: 'def', content: 'def'), + ], + ), + ], + ); const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, @@ -1303,30 +1334,38 @@ class _HomePageState extends State { windows: windowsNotificationDetails, ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _requestFullScreenIntentPermission() async { - final bool permissionGranted = await flutterLocalNotificationsPlugin + final bool permissionGranted = + await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.requestFullScreenIntentPermission() ?? false; await showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - content: Text( - 'Full screen intent permission granted: $permissionGranted'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + context: context, + builder: (BuildContext context) => AlertDialog( + content: Text( + 'Full screen intent permission granted: $permissionGranted', + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); } Future _showFullScreenNotification() async { @@ -1335,9 +1374,10 @@ class _HomePageState extends State { builder: (_) => AlertDialog( title: const Text('Turn off your screen'), content: const Text( - 'to see the full-screen intent in 5 seconds, press OK and TURN ' - 'OFF your screen. Note that the full-screen intent permission must ' - 'be granted for this to work too'), + 'to see the full-screen intent in 5 seconds, press OK and TURN ' + 'OFF your screen. Note that the full-screen intent permission must ' + 'be granted for this to work too', + ), actions: [ TextButton( onPressed: () { @@ -1348,23 +1388,27 @@ class _HomePageState extends State { TextButton( onPressed: () async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'scheduled title', - 'scheduled body', - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), - const NotificationDetails( - android: AndroidNotificationDetails( - 'full screen channel id', 'full screen channel name', - channelDescription: 'full screen channel description', - priority: Priority.high, - importance: Importance.high, - fullScreenIntent: true)), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); + 0, + 'scheduled title', + 'scheduled body', + tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), + const NotificationDetails( + android: AndroidNotificationDetails( + 'full screen channel id', + 'full screen channel name', + channelDescription: 'full screen channel description', + priority: Priority.high, + importance: Importance.high, + fullScreenIntent: true, + ), + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + ); Navigator.pop(context); }, child: const Text('OK'), - ) + ), ], ), ); @@ -1372,31 +1416,46 @@ class _HomePageState extends State { Future _showNotificationWithNoBody() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker'); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + ); const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', null, notificationDetails, - payload: 'item x'); + id++, + 'plain title', + null, + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithNoTitle() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker'); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + ); const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, ); - await flutterLocalNotificationsPlugin - .show(id++, null, 'plain body', notificationDetails, payload: 'item x'); + await flutterLocalNotificationsPlugin.show( + id++, + null, + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _cancelNotification() async { @@ -1410,26 +1469,24 @@ class _HomePageState extends State { Future _showNotificationCustomSound() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your other channel id', - 'your other channel name', - channelDescription: 'your other channel description', - sound: RawResourceAndroidNotificationSound('slow_spring_board'), - ); + 'your other channel id', + 'your other channel name', + channelDescription: 'your other channel description', + 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'), - ); + sound: AssetsLinuxSound('sound/slow_spring_board.mp3'), + ); final WindowsNotificationDetails windowsNotificationDetails = WindowsNotificationDetails( - audio: WindowsNotificationAudio.asset( - 'sound/slow_spring_board.mp3', - fallback: WindowsNotificationSound.alarm5, - ), - ); + audio: WindowsNotificationAudio.asset( + 'sound/slow_spring_board.mp3', + fallback: WindowsNotificationSound.alarm5, + ), + ); final NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, iOS: darwinNotificationDetails, @@ -1454,94 +1511,118 @@ class _HomePageState extends State { final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'other custom channel id', 'other custom channel name', - channelDescription: 'other custom channel description', - icon: 'secondary_icon', - largeIcon: const DrawableResourceAndroidBitmap('sample_large_icon'), - vibrationPattern: vibrationPattern, - enableLights: true, - color: const Color.fromARGB(255, 255, 0, 0), - ledColor: const Color.fromARGB(255, 255, 0, 0), - ledOnMs: 1000, - ledOffMs: 500); - - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'other custom channel id', + 'other custom channel name', + channelDescription: 'other custom channel description', + icon: 'secondary_icon', + largeIcon: const DrawableResourceAndroidBitmap('sample_large_icon'), + vibrationPattern: vibrationPattern, + enableLights: true, + color: const Color.fromARGB(255, 255, 0, 0), + ledColor: const Color.fromARGB(255, 255, 0, 0), + ledOnMs: 1000, + ledOffMs: 500, + ); + + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'title of notification with custom vibration pattern, LED and icon', - 'body of notification with custom vibration pattern, LED and icon', - notificationDetails); + id++, + 'title of notification with custom vibration pattern, LED and icon', + 'body of notification with custom vibration pattern, LED and icon', + notificationDetails, + ); } Future _zonedScheduleNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'scheduled title', - 'scheduled body', - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), - const NotificationDetails( - android: AndroidNotificationDetails( - 'your channel id', 'your channel name', - channelDescription: 'your channel description')), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); + 0, + 'scheduled title', + 'scheduled body', + tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), + const NotificationDetails( + android: AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + ), + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + ); } Future _zonedScheduleAlarmClockNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 123, - 'scheduled alarm clock title', - 'scheduled alarm clock body', - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), - const NotificationDetails( - android: AndroidNotificationDetails( - 'alarm_clock_channel', 'Alarm Clock Channel', - channelDescription: 'Alarm Clock Notification')), - androidScheduleMode: AndroidScheduleMode.alarmClock); + 123, + 'scheduled alarm clock title', + 'scheduled alarm clock body', + tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)), + const NotificationDetails( + android: AndroidNotificationDetails( + 'alarm_clock_channel', + 'Alarm Clock Channel', + channelDescription: 'Alarm Clock Notification', + ), + ), + androidScheduleMode: AndroidScheduleMode.alarmClock, + ); } Future _showNotificationWithNoSound() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('silent channel id', 'silent channel name', - channelDescription: 'silent channel description', - playSound: false, - styleInformation: DefaultStyleInformation(true, true)); + AndroidNotificationDetails( + 'silent channel id', + 'silent channel name', + channelDescription: 'silent channel description', + playSound: false, + styleInformation: DefaultStyleInformation(true, true), + ); const DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - presentSound: false, - ); + DarwinNotificationDetails(presentSound: false); final WindowsNotificationDetails windowsDetails = WindowsNotificationDetails(audio: WindowsNotificationAudio.silent()); final NotificationDetails notificationDetails = NotificationDetails( - windows: windowsDetails, - android: androidNotificationDetails, - iOS: darwinNotificationDetails, - macOS: darwinNotificationDetails); + windows: windowsDetails, + android: androidNotificationDetails, + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'silent title', 'silent body', notificationDetails); + id++, + 'silent title', + 'silent body', + notificationDetails, + ); } Future _showNotificationSilently() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - silent: true); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + silent: true, + ); const DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - presentSound: false, - ); + DarwinNotificationDetails(presentSound: false); final WindowsNotificationDetails windowsDetails = WindowsNotificationDetails(audio: WindowsNotificationAudio.silent()); final NotificationDetails notificationDetails = NotificationDetails( - windows: windowsDetails, - android: androidNotificationDetails, - iOS: darwinNotificationDetails, - macOS: darwinNotificationDetails); + windows: windowsDetails, + android: androidNotificationDetails, + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'silent title', 'silent body', notificationDetails); + id++, + 'silent title', + 'silent body', + notificationDetails, + ); } Future _showSoundUriNotification() async { @@ -1549,46 +1630,71 @@ class _HomePageState extends State { /// example app to return the Uri for the default alarm sound and uses /// as the notification sound final String? alarmUri = await platform.invokeMethod('getAlarmUri'); - final UriAndroidNotificationSound uriSound = - UriAndroidNotificationSound(alarmUri!); + final UriAndroidNotificationSound uriSound = UriAndroidNotificationSound( + alarmUri!, + ); final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('uri channel id', 'uri channel name', - channelDescription: 'uri channel description', - sound: uriSound, - styleInformation: const DefaultStyleInformation(true, true)); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'uri channel id', + 'uri channel name', + channelDescription: 'uri channel description', + sound: uriSound, + styleInformation: const DefaultStyleInformation(true, true), + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'uri sound title', 'uri sound body', notificationDetails); + id++, + 'uri sound title', + 'uri sound body', + notificationDetails, + ); } Future _showTimeoutNotification() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('silent channel id', 'silent channel name', - channelDescription: 'silent channel description', - timeoutAfter: 3000, - styleInformation: DefaultStyleInformation(true, true)); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - await flutterLocalNotificationsPlugin.show(id++, 'timeout notification', - 'Times out after 3 seconds', notificationDetails); + AndroidNotificationDetails( + 'silent channel id', + 'silent channel name', + channelDescription: 'silent channel description', + timeoutAfter: 3000, + styleInformation: DefaultStyleInformation(true, true), + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); + await flutterLocalNotificationsPlugin.show( + id++, + 'timeout notification', + 'Times out after 3 seconds', + notificationDetails, + ); } Future _showInsistentNotification() async { // This value is from: https://developer.android.com/reference/android/app/Notification.html#FLAG_INSISTENT const int insistentFlag = 4; final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - additionalFlags: Int32List.fromList([insistentFlag])); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + additionalFlags: Int32List.fromList([insistentFlag]), + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'insistent title', 'insistent body', notificationDetails, - payload: 'item x'); + id++, + 'insistent title', + 'insistent body', + notificationDetails, + payload: 'item x', + ); } Future _downloadAndSaveFile(String url, String fileName) async { @@ -1601,26 +1707,39 @@ class _HomePageState extends State { } Future _showBigPictureNotification() async { - final String largeIconPath = - await _downloadAndSaveFile('https://dummyimage.com/48x48', 'largeIcon'); + final String largeIconPath = await _downloadAndSaveFile( + 'https://dummyimage.com/48x48', + 'largeIcon', + ); final String bigPicturePath = await _downloadAndSaveFile( - 'https://dummyimage.com/400x800', 'bigPicture'); + 'https://dummyimage.com/400x800', + 'bigPicture', + ); final BigPictureStyleInformation bigPictureStyleInformation = - BigPictureStyleInformation(FilePathAndroidBitmap(bigPicturePath), - largeIcon: FilePathAndroidBitmap(largeIconPath), - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + BigPictureStyleInformation( + FilePathAndroidBitmap(bigPicturePath), + largeIcon: FilePathAndroidBitmap(largeIconPath), + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true, + ); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'big text channel id', 'big text channel name', - channelDescription: 'big text channel description', - styleInformation: bigPictureStyleInformation); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'big text channel id', + 'big text channel name', + channelDescription: 'big text channel description', + styleInformation: bigPictureStyleInformation, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'big text title', 'silent body', notificationDetails); + id++, + 'big text title', + 'silent body', + notificationDetails, + ); } Future _base64encodedImage(String url) async { @@ -1630,29 +1749,40 @@ class _HomePageState extends State { } Future _showBigPictureNotificationBase64() async { - final String largeIcon = - await _base64encodedImage('https://dummyimage.com/48x48'); - final String bigPicture = - await _base64encodedImage('https://dummyimage.com/400x800'); + final String largeIcon = await _base64encodedImage( + 'https://dummyimage.com/48x48', + ); + final String bigPicture = await _base64encodedImage( + 'https://dummyimage.com/400x800', + ); final BigPictureStyleInformation bigPictureStyleInformation = BigPictureStyleInformation( - ByteArrayAndroidBitmap.fromBase64String( - bigPicture), //Base64AndroidBitmap(bigPicture), - largeIcon: ByteArrayAndroidBitmap.fromBase64String(largeIcon), - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + ByteArrayAndroidBitmap.fromBase64String( + bigPicture, + ), //Base64AndroidBitmap(bigPicture), + largeIcon: ByteArrayAndroidBitmap.fromBase64String(largeIcon), + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true, + ); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'big text channel id', 'big text channel name', - channelDescription: 'big text channel description', - styleInformation: bigPictureStyleInformation); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'big text channel id', + 'big text channel name', + channelDescription: 'big text channel description', + styleInformation: bigPictureStyleInformation, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'big text title', 'silent body', notificationDetails); + id++, + 'big text title', + 'silent body', + notificationDetails, + ); } Future _getByteArrayFromUrl(String url) async { @@ -1662,72 +1792,103 @@ class _HomePageState extends State { Future _showBigPictureNotificationURL() async { final ByteArrayAndroidBitmap largeIcon = ByteArrayAndroidBitmap( - await _getByteArrayFromUrl('https://dummyimage.com/48x48')); + await _getByteArrayFromUrl('https://dummyimage.com/48x48'), + ); final ByteArrayAndroidBitmap bigPicture = ByteArrayAndroidBitmap( - await _getByteArrayFromUrl('https://dummyimage.com/400x800')); + await _getByteArrayFromUrl('https://dummyimage.com/400x800'), + ); final BigPictureStyleInformation bigPictureStyleInformation = - BigPictureStyleInformation(bigPicture, - largeIcon: largeIcon, - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + BigPictureStyleInformation( + bigPicture, + largeIcon: largeIcon, + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true, + ); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'big text channel id', 'big text channel name', - channelDescription: 'big text channel description', - styleInformation: bigPictureStyleInformation); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'big text channel id', + 'big text channel name', + channelDescription: 'big text channel description', + styleInformation: bigPictureStyleInformation, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'big text title', 'silent body', notificationDetails); + id++, + 'big text title', + 'silent body', + notificationDetails, + ); } Future _showBigPictureNotificationHiddenLargeIcon() async { - final String largeIconPath = - await _downloadAndSaveFile('https://dummyimage.com/48x48', 'largeIcon'); + final String largeIconPath = await _downloadAndSaveFile( + 'https://dummyimage.com/48x48', + 'largeIcon', + ); final String bigPicturePath = await _downloadAndSaveFile( - 'https://dummyimage.com/400x800', 'bigPicture'); + 'https://dummyimage.com/400x800', + 'bigPicture', + ); final BigPictureStyleInformation bigPictureStyleInformation = - BigPictureStyleInformation(FilePathAndroidBitmap(bigPicturePath), - hideExpandedLargeIcon: true, - contentTitle: 'overridden big content title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + BigPictureStyleInformation( + FilePathAndroidBitmap(bigPicturePath), + hideExpandedLargeIcon: true, + contentTitle: 'overridden big content title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true, + ); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'big text channel id', 'big text channel name', - channelDescription: 'big text channel description', - largeIcon: FilePathAndroidBitmap(largeIconPath), - styleInformation: bigPictureStyleInformation); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'big text channel id', + 'big text channel name', + channelDescription: 'big text channel description', + largeIcon: FilePathAndroidBitmap(largeIconPath), + styleInformation: bigPictureStyleInformation, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'big text title', 'silent body', notificationDetails); + id++, + 'big text title', + 'silent body', + notificationDetails, + ); } Future _showNotificationMediaStyle() async { final String largeIconPath = await _downloadAndSaveFile( - 'https://dummyimage.com/128x128/00FF00/000000', 'largeIcon'); + 'https://dummyimage.com/128x128/00FF00/000000', + 'largeIcon', + ); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'media channel id', - 'media channel name', - channelDescription: 'media channel description', - largeIcon: FilePathAndroidBitmap(largeIconPath), - styleInformation: const MediaStyleInformation(), - ); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'media channel id', + 'media channel name', + channelDescription: 'media channel description', + largeIcon: FilePathAndroidBitmap(largeIconPath), + styleInformation: const MediaStyleInformation(), + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'notification title', 'notification body', notificationDetails); + id++, + 'notification title', + 'notification body', + notificationDetails, + ); } Future _showBigTextNotification() async { - const BigTextStyleInformation bigTextStyleInformation = - BigTextStyleInformation( + const BigTextStyleInformation + bigTextStyleInformation = BigTextStyleInformation( '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', @@ -1737,40 +1898,58 @@ class _HomePageState extends State { ); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'big text channel id', 'big text channel name', - channelDescription: 'big text channel description', - styleInformation: bigTextStyleInformation); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'big text channel id', + 'big text channel name', + channelDescription: 'big text channel description', + styleInformation: bigTextStyleInformation, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'big text title', 'silent body', notificationDetails); + id++, + 'big text title', + 'silent body', + notificationDetails, + ); } Future _showInboxNotification() async { final List lines = ['line 1', 'line 2']; final InboxStyleInformation inboxStyleInformation = InboxStyleInformation( - lines, - htmlFormatLines: true, - contentTitle: 'overridden inbox context title', - htmlFormatContentTitle: true, - summaryText: 'summary text', - htmlFormatSummaryText: true); + lines, + htmlFormatLines: true, + contentTitle: 'overridden inbox context title', + htmlFormatContentTitle: true, + summaryText: 'summary text', + htmlFormatSummaryText: true, + ); final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('inbox channel id', 'inboxchannel name', - channelDescription: 'inbox channel description', - styleInformation: inboxStyleInformation); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'inbox channel id', + 'inboxchannel name', + channelDescription: 'inbox channel description', + styleInformation: inboxStyleInformation, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'inbox title', 'inbox body', notificationDetails); + id++, + 'inbox title', + 'inbox body', + notificationDetails, + ); } Future _showMessagingNotification() async { // use a platform channel to resolve an Android drawable resource to a URI. // This is NOT part of the notifications plugin. Calls made over this /// channel is handled by the app - final String? imageUri = - await platform.invokeMethod('drawableToUri', 'food'); + final String? imageUri = await platform.invokeMethod( + 'drawableToUri', + 'food', + ); /// First two person objects will use icons that part of the Android app's /// drawable resources @@ -1787,8 +1966,10 @@ class _HomePageState extends State { icon: FlutterBitmapAssetAndroidIcon('icons/coworker.png'), ); // download the icon that would be use for the lunch bot person - final String largeIconPath = - await _downloadAndSaveFile('https://dummyimage.com/48x48', 'largeIcon'); + final String largeIconPath = await _downloadAndSaveFile( + 'https://dummyimage.com/48x48', + 'largeIcon', + ); // this person object will use an icon that was downloaded final Person lunchBot = Person( name: 'Lunch bot', @@ -1797,46 +1978,80 @@ class _HomePageState extends State { icon: BitmapFilePathAndroidIcon(largeIconPath), ); final Person chef = Person( - name: 'Master Chef', - key: '3', - uri: 'tel:111222333444', - icon: ByteArrayAndroidIcon.fromBase64String( - await _base64encodedImage('https://placekitten.com/48/48'))); + name: 'Master Chef', + key: '3', + uri: 'tel:111222333444', + icon: ByteArrayAndroidIcon.fromBase64String( + await _base64encodedImage('https://placekitten.com/48/48'), + ), + ); final List messages = [ Message('Hi', DateTime.now(), null), - Message("What's up?", DateTime.now().add(const Duration(minutes: 5)), - coworker), - Message('Lunch?', DateTime.now().add(const Duration(minutes: 10)), null, - dataMimeType: 'image/png', dataUri: imageUri), - Message('What kind of food would you prefer?', - DateTime.now().add(const Duration(minutes: 10)), lunchBot), - Message('You do not have time eat! Keep working!', - DateTime.now().add(const Duration(minutes: 11)), chef), + Message( + "What's up?", + DateTime.now().add(const Duration(minutes: 5)), + coworker, + ), + Message( + 'Lunch?', + DateTime.now().add(const Duration(minutes: 10)), + null, + dataMimeType: 'image/png', + dataUri: imageUri, + ), + Message( + 'What kind of food would you prefer?', + DateTime.now().add(const Duration(minutes: 10)), + lunchBot, + ), + Message( + 'You do not have time eat! Keep working!', + DateTime.now().add(const Duration(minutes: 11)), + chef, + ), ]; final MessagingStyleInformation messagingStyle = MessagingStyleInformation( - me, - groupConversation: true, - conversationTitle: 'Team lunch', - htmlFormatContent: true, - htmlFormatTitle: true, - messages: messages); + me, + groupConversation: true, + conversationTitle: 'Team lunch', + htmlFormatContent: true, + htmlFormatTitle: true, + messages: messages, + ); final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('message channel id', 'message channel name', - channelDescription: 'message channel description', - category: AndroidNotificationCategory.message, - styleInformation: messagingStyle); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'message channel id', + 'message channel name', + channelDescription: 'message channel description', + category: AndroidNotificationCategory.message, + styleInformation: messagingStyle, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id, 'message title', 'message body', notificationDetails); + id, + 'message title', + 'message body', + notificationDetails, + ); // wait 10 seconds and add another message to simulate another response await Future.delayed(const Duration(seconds: 10), () async { - messages.add(Message("I'm so sorry!!! But I really like thai food ...", - DateTime.now().add(const Duration(minutes: 11)), null)); + messages.add( + Message( + "I'm so sorry!!! But I really like thai food ...", + DateTime.now().add(const Duration(minutes: 11)), + null, + ), + ); await flutterLocalNotificationsPlugin.show( - id++, 'message title', 'message body', notificationDetails); + id++, + 'message title', + 'message body', + notificationDetails, + ); }); } @@ -1847,28 +2062,39 @@ class _HomePageState extends State { const String groupChannelDescription = 'grouped channel description'; // example based on https://developer.android.com/training/notify-user/group.html const AndroidNotificationDetails firstNotificationAndroidSpecifics = - AndroidNotificationDetails(groupChannelId, groupChannelName, - channelDescription: groupChannelDescription, - importance: Importance.max, - priority: Priority.high, - groupKey: groupKey); + AndroidNotificationDetails( + groupChannelId, + groupChannelName, + channelDescription: groupChannelDescription, + importance: Importance.max, + priority: Priority.high, + groupKey: groupKey, + ); const NotificationDetails firstNotificationPlatformSpecifics = NotificationDetails(android: firstNotificationAndroidSpecifics); - await flutterLocalNotificationsPlugin.show(id++, 'Alex Faarborg', - 'You will not believe...', firstNotificationPlatformSpecifics); + await flutterLocalNotificationsPlugin.show( + id++, + 'Alex Faarborg', + 'You will not believe...', + firstNotificationPlatformSpecifics, + ); const AndroidNotificationDetails secondNotificationAndroidSpecifics = - AndroidNotificationDetails(groupChannelId, groupChannelName, - channelDescription: groupChannelDescription, - importance: Importance.max, - priority: Priority.high, - groupKey: groupKey); + AndroidNotificationDetails( + groupChannelId, + groupChannelName, + channelDescription: groupChannelDescription, + importance: Importance.max, + priority: Priority.high, + groupKey: groupKey, + ); const NotificationDetails secondNotificationPlatformSpecifics = NotificationDetails(android: secondNotificationAndroidSpecifics); await flutterLocalNotificationsPlugin.show( - id++, - 'Jeff Chang', - 'Please join us to celebrate the...', - secondNotificationPlatformSpecifics); + id++, + 'Jeff Chang', + 'Please join us to celebrate the...', + secondNotificationPlatformSpecifics, + ); // Create the summary notification to support older devices that pre-date /// Android 7.0 (API level 24). @@ -1877,36 +2103,52 @@ class _HomePageState extends State { /// mentioned in https://developer.android.com/training/notify-user/group const List lines = [ 'Alex Faarborg Check this out', - 'Jeff Chang Launch Party' + 'Jeff Chang Launch Party', ]; const InboxStyleInformation inboxStyleInformation = InboxStyleInformation( - lines, - contentTitle: '2 messages', - summaryText: 'janedoe@example.com'); + lines, + contentTitle: '2 messages', + summaryText: 'janedoe@example.com', + ); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails(groupChannelId, groupChannelName, - channelDescription: groupChannelDescription, - styleInformation: inboxStyleInformation, - groupKey: groupKey, - setAsGroupSummary: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + groupChannelId, + groupChannelName, + channelDescription: groupChannelDescription, + styleInformation: inboxStyleInformation, + groupKey: groupKey, + setAsGroupSummary: true, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'Attention', 'Two messages', notificationDetails); + id++, + 'Attention', + 'Two messages', + notificationDetails, + ); } Future _showNotificationWithTag() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - tag: 'tag'); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + tag: 'tag', + ); const NotificationDetails notificationDetails = NotificationDetails( android: androidNotificationDetails, ); await flutterLocalNotificationsPlugin.show( - id++, 'first notification', null, notificationDetails); + id++, + 'first notification', + null, + notificationDetails, + ); } Future _checkPendingNotificationRequests() async { @@ -1915,9 +2157,10 @@ class _HomePageState extends State { return showDialog( context: context, builder: (BuildContext context) => AlertDialog( - content: - Text('${pendingNotificationRequests.length} pending notification ' - 'requests'), + content: Text( + '${pendingNotificationRequests.length} pending notification ' + 'requests', + ), actions: [ TextButton( onPressed: () { @@ -1940,34 +2183,47 @@ class _HomePageState extends State { Future _showOngoingNotification() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ongoing: true, - autoCancel: false); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ongoing: true, + autoCancel: false, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'ongoing notification title', - 'ongoing notification body', - notificationDetails); + id++, + 'ongoing notification title', + 'ongoing notification body', + notificationDetails, + ); } Future _showNotificationWithNoBadge() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('no badge channel', 'no badge name', - channelDescription: 'no badge description', - channelShowBadge: false, - importance: Importance.max, - priority: Priority.high, - onlyAlertOnce: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'no badge channel', + 'no badge name', + channelDescription: 'no badge description', + channelShowBadge: false, + importance: Importance.max, + priority: Priority.high, + onlyAlertOnce: true, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'no badge title', 'no badge body', notificationDetails, - payload: 'item x'); + id++, + 'no badge title', + 'no badge body', + notificationDetails, + payload: 'item x', + ); } Future _showProgressNotification() async { @@ -1977,23 +2233,28 @@ class _HomePageState extends State { for (int i = 0; i <= maxProgress; i++) { await Future.delayed(const Duration(seconds: 1), () async { final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('progress channel', 'progress channel', - channelDescription: 'progress channel description', - channelShowBadge: false, - importance: Importance.max, - priority: Priority.high, - onlyAlertOnce: true, - showProgress: true, - maxProgress: maxProgress, - progress: i); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'progress channel', + 'progress channel', + channelDescription: 'progress channel description', + channelShowBadge: false, + importance: Importance.max, + priority: Priority.high, + onlyAlertOnce: true, + showProgress: true, + maxProgress: maxProgress, + progress: i, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - progressId, - 'progress notification title', - 'progress notification body', - notificationDetails, - payload: 'item x'); + progressId, + 'progress notification title', + 'progress notification body', + notificationDetails, + payload: 'item x', + ); }); } } @@ -2001,82 +2262,103 @@ class _HomePageState extends State { Future _showIndeterminateProgressNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'indeterminate progress channel', 'indeterminate progress channel', - channelDescription: 'indeterminate progress channel description', - channelShowBadge: false, - importance: Importance.max, - priority: Priority.high, - onlyAlertOnce: true, - showProgress: true, - indeterminate: true); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'indeterminate progress channel', + 'indeterminate progress channel', + channelDescription: 'indeterminate progress channel description', + channelShowBadge: false, + importance: Importance.max, + priority: Priority.high, + onlyAlertOnce: true, + showProgress: true, + indeterminate: true, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'indeterminate progress notification title', - 'indeterminate progress notification body', - notificationDetails, - payload: 'item x'); + id++, + 'indeterminate progress notification title', + 'indeterminate progress notification body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationUpdateChannelDescription() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your updated channel description', - importance: Importance.max, - priority: Priority.high, - channelAction: AndroidNotificationChannelAction.update); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your updated channel description', + importance: Importance.max, + priority: Priority.high, + channelAction: AndroidNotificationChannelAction.update, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'updated notification channel', - 'check settings to see updated channel description', - notificationDetails, - payload: 'item x'); + id++, + 'updated notification channel', + 'check settings to see updated channel description', + notificationDetails, + payload: 'item x', + ); } Future _showPublicNotification() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - visibility: NotificationVisibility.public); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + visibility: NotificationVisibility.public, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'public notification title', - 'public notification body', - notificationDetails, - payload: 'item x'); + id++, + 'public notification title', + 'public notification body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithSubtitle() async { const DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - subtitle: 'the subtitle', - ); + DarwinNotificationDetails(subtitle: 'the subtitle'); const NotificationDetails notificationDetails = NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'title of notification with a subtitle', - 'body of notification with a subtitle', - notificationDetails, - payload: 'item x'); + id++, + 'title of notification with a subtitle', + 'body of notification with a subtitle', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithIconBadge() async { const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails(badgeNumber: 1); const NotificationDetails notificationDetails = NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'icon badge title', 'icon badge body', notificationDetails, - payload: 'item x'); + id++, + 'icon badge title', + 'icon badge body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationsWithThreadIdentifier() async { @@ -2084,11 +2366,11 @@ class _HomePageState extends State { String threadIdentifier, ) { final DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - threadIdentifier: threadIdentifier, - ); + DarwinNotificationDetails(threadIdentifier: threadIdentifier); return NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); } final NotificationDetails thread1PlatformChannelSpecifics = @@ -2096,185 +2378,245 @@ class _HomePageState extends State { final NotificationDetails thread2PlatformChannelSpecifics = buildNotificationDetailsForThread('thread2'); - await flutterLocalNotificationsPlugin.show(id++, 'thread 1', - 'first notification', thread1PlatformChannelSpecifics); - await flutterLocalNotificationsPlugin.show(id++, 'thread 1', - 'second notification', thread1PlatformChannelSpecifics); - await flutterLocalNotificationsPlugin.show(id++, 'thread 1', - 'third notification', thread1PlatformChannelSpecifics); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 1', + 'first notification', + thread1PlatformChannelSpecifics, + ); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 1', + 'second notification', + thread1PlatformChannelSpecifics, + ); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 1', + 'third notification', + thread1PlatformChannelSpecifics, + ); - await flutterLocalNotificationsPlugin.show(id++, 'thread 2', - 'first notification', thread2PlatformChannelSpecifics); - await flutterLocalNotificationsPlugin.show(id++, 'thread 2', - 'second notification', thread2PlatformChannelSpecifics); - await flutterLocalNotificationsPlugin.show(id++, 'thread 2', - 'third notification', thread2PlatformChannelSpecifics); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 2', + 'first notification', + thread2PlatformChannelSpecifics, + ); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 2', + 'second notification', + thread2PlatformChannelSpecifics, + ); + await flutterLocalNotificationsPlugin.show( + id++, + 'thread 2', + 'third notification', + thread2PlatformChannelSpecifics, + ); } Future _showNotificationWithTimeSensitiveInterruptionLevel() async { const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - interruptionLevel: InterruptionLevel.timeSensitive, - ); + interruptionLevel: InterruptionLevel.timeSensitive, + ); const NotificationDetails notificationDetails = NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'title of time sensitive notification', - 'body of time sensitive notification', - notificationDetails, - payload: 'item x'); + id++, + 'title of time sensitive notification', + 'body of time sensitive notification', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithBannerNotInNotificationCentre() async { const DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - presentBanner: true, - presentList: false, - ); + DarwinNotificationDetails(presentBanner: true, presentList: false); const NotificationDetails notificationDetails = NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'title of banner notification', - 'body of banner notification', - notificationDetails, - payload: 'item x'); + id++, + 'title of banner notification', + 'body of banner notification', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationInNotificationCentreOnly() async { const DarwinNotificationDetails darwinNotificationDetails = - DarwinNotificationDetails( - presentBanner: false, - presentList: true, + DarwinNotificationDetails(presentBanner: false, presentList: true); + const NotificationDetails notificationDetails = NotificationDetails( + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, ); - 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'); + id++, + 'title of notification shown only in notification centre', + 'body of notification shown only in notification centre', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithoutTimestamp() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - showWhen: false); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + showWhen: false, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithCustomTimestamp() async { final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithCustomSubText() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - showWhen: false, - subText: 'custom subtext', + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + showWhen: false, + subText: 'custom subtext', + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithChronometer() async { final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, - usesChronometer: true, - chronometerCountDown: true, + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, + usesChronometer: true, + chronometerCountDown: true, + ); + final NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, ); - final NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( - id++, 'plain title', 'plain body', notificationDetails, - payload: 'item x'); + id++, + 'plain title', + 'plain body', + notificationDetails, + payload: 'item x', + ); } Future _showNotificationWithAttachment({ required bool hideThumbnail, }) async { final String bigPicturePath = await _downloadAndSaveFile( - 'https://dummyimage.com/600x200', 'bigPicture.jpg'); + 'https://dummyimage.com/600x200', + 'bigPicture.jpg', + ); final DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - attachments: [ - DarwinNotificationAttachment( - bigPicturePath, - hideThumbnail: hideThumbnail, - ) - ], - ); + attachments: [ + DarwinNotificationAttachment( + bigPicturePath, + hideThumbnail: hideThumbnail, + ), + ], + ); final NotificationDetails notificationDetails = NotificationDetails( - iOS: darwinNotificationDetails, macOS: darwinNotificationDetails); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'notification with attachment title', - 'notification with attachment body', - notificationDetails); + id++, + 'notification with attachment title', + 'notification with attachment body', + notificationDetails, + ); } Future _showNotificationWithClippedThumbnailAttachment() async { final String bigPicturePath = await _downloadAndSaveFile( - 'https://dummyimage.com/600x200', 'bigPicture.jpg'); + 'https://dummyimage.com/600x200', + 'bigPicture.jpg', + ); final DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - attachments: [ - DarwinNotificationAttachment( - bigPicturePath, - thumbnailClippingRect: - // lower right quadrant of the attachment - const DarwinNotificationAttachmentThumbnailClippingRect( - x: 0.5, - y: 0.5, - height: 0.5, - width: 0.5, - ), - ) - ], - ); + attachments: [ + 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); + iOS: darwinNotificationDetails, + macOS: darwinNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( - id++, - 'notification with attachment title', - 'notification with attachment body', - notificationDetails); + id++, + 'notification with attachment title', + 'notification with attachment body', + notificationDetails, + ); } Future _createNotificationChannelGroup() async { @@ -2282,51 +2624,68 @@ class _HomePageState extends State { // create the group first const AndroidNotificationChannelGroup androidNotificationChannelGroup = AndroidNotificationChannelGroup( - channelGroupId, 'your channel group name', - description: 'your channel group description'); + channelGroupId, + 'your channel group name', + description: 'your channel group description', + ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .createNotificationChannelGroup(androidNotificationChannelGroup); // create channels associated with the group await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! - .createNotificationChannel(const AndroidNotificationChannel( - 'grouped channel id 1', 'grouped channel name 1', + AndroidFlutterLocalNotificationsPlugin + >()! + .createNotificationChannel( + const AndroidNotificationChannel( + 'grouped channel id 1', + 'grouped channel name 1', description: 'grouped channel description 1', - groupId: channelGroupId)); + groupId: channelGroupId, + ), + ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! - .createNotificationChannel(const AndroidNotificationChannel( - 'grouped channel id 2', 'grouped channel name 2', + AndroidFlutterLocalNotificationsPlugin + >()! + .createNotificationChannel( + const AndroidNotificationChannel( + 'grouped channel id 2', + 'grouped channel name 2', description: 'grouped channel description 2', - groupId: channelGroupId)); + groupId: channelGroupId, + ), + ); await showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - content: Text('Channel group with name ' - '${androidNotificationChannelGroup.name} created'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + context: context, + builder: (BuildContext context) => AlertDialog( + content: Text( + 'Channel group with name ' + '${androidNotificationChannelGroup.name} created', + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); } Future _deleteNotificationChannelGroup() async { const String channelGroupId = 'your channel group id'; await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.deleteNotificationChannelGroup(channelGroupId); await showDialog( @@ -2347,90 +2706,112 @@ class _HomePageState extends State { Future _startForegroundService() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker'); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() - ?.startForegroundService(1, 'plain title', 'plain body', - notificationDetails: androidNotificationDetails, payload: 'item x'); + AndroidFlutterLocalNotificationsPlugin + >() + ?.startForegroundService( + 1, + 'plain title', + 'plain body', + notificationDetails: androidNotificationDetails, + payload: 'item x', + ); } Future _startForegroundServiceWithBlueBackgroundNotification() async { const AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails( - 'your channel id', - 'your channel name', - channelDescription: 'color background channel description', - importance: Importance.max, - priority: Priority.high, - ticker: 'ticker', - color: Colors.blue, - colorized: true, - ); + 'your channel id', + 'your channel name', + channelDescription: 'color background channel description', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + color: Colors.blue, + colorized: true, + ); /// only using foreground service can color the background await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.startForegroundService( - 1, 'colored background text title', 'colored background text body', - notificationDetails: androidPlatformChannelSpecifics, - payload: 'item x'); + 1, + 'colored background text title', + 'colored background text body', + notificationDetails: androidPlatformChannelSpecifics, + payload: 'item x', + ); } Future _stopForegroundService() async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.stopForegroundService(); } Future _createNotificationChannel() async { const AndroidNotificationChannel androidNotificationChannel = AndroidNotificationChannel( - 'your channel id 2', - 'your channel name 2', - description: 'your channel description 2', - ); + 'your channel id 2', + 'your channel name 2', + description: 'your channel description 2', + ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.createNotificationChannel(androidNotificationChannel); await showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - content: - Text('Channel with name ${androidNotificationChannel.name} ' - 'created'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + context: context, + builder: (BuildContext context) => AlertDialog( + content: Text( + 'Channel with name ${androidNotificationChannel.name} ' + 'created', + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); } Future _createNotificationChannelWithDndBypass() async { const AndroidNotificationChannel androidNotificationChannel = - AndroidNotificationChannel('your channel id 3', 'your channel name 3', - description: 'your channel description 3', - bypassDnd: true, - importance: Importance.max); + AndroidNotificationChannel( + 'your channel id 3', + 'your channel name 3', + description: 'your channel description 3', + bypassDnd: true, + importance: Importance.max, + ); final AndroidFlutterLocalNotificationsPlugin? androidPlugin = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin + >(); - final bool? hasPolicyAccess = - await androidPlugin?.hasNotificationPolicyAccess(); + final bool? hasPolicyAccess = await androidPlugin + ?.hasNotificationPolicyAccess(); if (hasPolicyAccess ?? false) { await androidPlugin?.requestNotificationPolicyAccess(); } @@ -2441,12 +2822,13 @@ class _HomePageState extends State { context: context, builder: (BuildContext context) => AlertDialog( content: Text( - 'Channel with name ${androidNotificationChannel.name} created'), + 'Channel with name ${androidNotificationChannel.name} created', + ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('OK'), - ) + ), ], ), ); @@ -2454,12 +2836,16 @@ class _HomePageState extends State { Future _showNotificationWithDndBypass() async { const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('your channel id 3', 'your channel name 3', - channelDescription: 'your channel description 3', - channelBypassDnd: true, - importance: Importance.max); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + AndroidNotificationDetails( + 'your channel id 3', + 'your channel name 3', + channelDescription: 'your channel description 3', + channelBypassDnd: true, + importance: Importance.max, + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.show( id++, @@ -2472,37 +2858,43 @@ class _HomePageState extends State { Future _areNotifcationsEnabledOnAndroid() async { final bool? areEnabled = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.areNotificationsEnabled(); await showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - content: Text(areEnabled == null - ? 'ERROR: received null' - : (areEnabled - ? 'Notifications are enabled' - : 'Notifications are NOT enabled')), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + context: context, + builder: (BuildContext context) => AlertDialog( + content: Text( + areEnabled == null + ? 'ERROR: received null' + : (areEnabled + ? 'Notifications are enabled' + : 'Notifications are NOT enabled'), + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); } Future _checkNotificationsOnCupertino() async { final NotificationsEnabledOptions? isEnabled = await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.checkPermissions() ?? - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() - ?.checkPermissions(); + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin + >() + ?.checkPermissions() ?? + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + MacOSFlutterLocalNotificationsPlugin + >() + ?.checkPermissions(); final String isEnabledString = isEnabled == null ? 'ERROR: received null' : ''' @@ -2514,25 +2906,27 @@ class _HomePageState extends State { isCriticalEnabled: ${isEnabled.isCriticalEnabled} '''; await showDialog( - context: context, - builder: (BuildContext context) => AlertDialog( - content: Text(isEnabledString), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('OK'), - ), - ], - )); + context: context, + builder: (BuildContext context) => AlertDialog( + content: Text(isEnabledString), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('OK'), + ), + ], + ), + ); } Future _deleteNotificationChannel() async { const String channelId = 'your channel id 2'; await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.deleteNotificationChannel(channelId); await showDialog( @@ -2629,7 +3023,9 @@ class _HomePageState extends State { child: const Text('Get messaging style'), onPressed: () { _getActiveNotificationMessagingStyle( - activeNotification.id!, activeNotification.tag); + activeNotification.id!, + activeNotification.tag, + ); }, ), ], @@ -2653,36 +3049,42 @@ class _HomePageState extends State { final MessagingStyleInformation? messagingStyle = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .getActiveNotificationMessagingStyle(id, tag: tag); if (messagingStyle == null) { dialogContent = const Text('No messaging style'); } else { dialogContent = SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text('person: ${_formatPerson(messagingStyle.person)}\n' + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'person: ${_formatPerson(messagingStyle.person)}\n' 'conversationTitle: ${messagingStyle.conversationTitle}\n' - 'groupConversation: ${messagingStyle.groupConversation}'), - const Divider(color: Colors.black), - if (messagingStyle.messages == null) const Text('No messages'), - if (messagingStyle.messages != null) - for (final Message msg in messagingStyle.messages!) - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('text: ${msg.text}\n' + 'groupConversation: ${messagingStyle.groupConversation}', + ), + const Divider(color: Colors.black), + if (messagingStyle.messages == null) const Text('No messages'), + if (messagingStyle.messages != null) + for (final Message msg in messagingStyle.messages!) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'text: ${msg.text}\n' 'timestamp: ${msg.timestamp}\n' 'person: ${_formatPerson(msg.person)}\n' 'dataMimeType: ${msg.dataMimeType}\n' - 'dataUri: ${msg.dataUri}'), - const Divider(color: Colors.black), - ], - ), - ], - )); + 'dataUri: ${msg.dataUri}', + ), + const Divider(color: Colors.black), + ], + ), + ], + ), + ); } } on PlatformException catch (error) { dialogContent = Text( @@ -2773,7 +3175,8 @@ class _HomePageState extends State { final List? channels = await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .getNotificationChannels(); return Container( @@ -2792,20 +3195,22 @@ class _HomePageState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('id: ${channel.id}\n' - 'name: ${channel.name}\n' - 'description: ${channel.description}\n' - 'groupId: ${channel.groupId}\n' - 'importance: ${channel.importance.value}\n' - 'bypassDnd: ${channel.bypassDnd}\n' - 'playSound: ${channel.playSound}\n' - 'sound: ${channel.sound?.sound}\n' - 'enableVibration: ${channel.enableVibration}\n' - 'vibrationPattern: ${channel.vibrationPattern}\n' - 'showBadge: ${channel.showBadge}\n' - 'enableLights: ${channel.enableLights}\n' - 'ledColor: ${channel.ledColor}\n' - 'audioAttributesUsage: ${channel.audioAttributesUsage}\n'), + Text( + 'id: ${channel.id}\n' + 'name: ${channel.name}\n' + 'description: ${channel.description}\n' + 'groupId: ${channel.groupId}\n' + 'importance: ${channel.importance.value}\n' + 'bypassDnd: ${channel.bypassDnd}\n' + 'playSound: ${channel.playSound}\n' + 'sound: ${channel.sound?.sound}\n' + 'enableVibration: ${channel.enableVibration}\n' + 'vibrationPattern: ${channel.vibrationPattern}\n' + 'showBadge: ${channel.showBadge}\n' + 'enableLights: ${channel.enableLights}\n' + 'ledColor: ${channel.ledColor}\n' + 'audioAttributesUsage: ${channel.audioAttributesUsage}\n', + ), const Divider(color: Colors.black), ], ), @@ -2823,30 +3228,39 @@ class _HomePageState extends State { Future _showNotificationWithNumber() async { const AndroidNotificationDetails androidPlatformChannelSpecifics = - AndroidNotificationDetails('your channel id', 'your channel name', - channelDescription: 'your channel description', - importance: Importance.max, - priority: Priority.high, - number: 1); - const NotificationDetails platformChannelSpecifics = - NotificationDetails(android: androidPlatformChannelSpecifics); + AndroidNotificationDetails( + 'your channel id', + 'your channel name', + channelDescription: 'your channel description', + importance: Importance.max, + priority: Priority.high, + number: 1, + ); + const NotificationDetails platformChannelSpecifics = NotificationDetails( + android: androidPlatformChannelSpecifics, + ); await flutterLocalNotificationsPlugin.show( - 0, 'icon badge title', 'icon badge body', platformChannelSpecifics, - payload: 'item x'); + 0, + 'icon badge title', + 'icon badge body', + platformChannelSpecifics, + payload: 'item x', + ); } Future _showNotificationWithAudioAttributeAlarm() async { const AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails( - 'your alarm channel id', - 'your alarm channel name', - channelDescription: 'your alarm channel description', - importance: Importance.max, - priority: Priority.high, - audioAttributesUsage: AudioAttributesUsage.alarm, + 'your alarm channel id', + 'your alarm channel name', + channelDescription: 'your alarm channel description', + importance: Importance.max, + priority: Priority.high, + audioAttributesUsage: AudioAttributesUsage.alarm, + ); + const NotificationDetails platformChannelSpecifics = NotificationDetails( + android: androidPlatformChannelSpecifics, ); - const NotificationDetails platformChannelSpecifics = - NotificationDetails(android: androidPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.show( 0, 'notification sound controlled by alarm volume', @@ -2858,11 +3272,11 @@ class _HomePageState extends State { Future _showNotificationWithCriticalSound() async { const DarwinNotificationDetails darwinNotificationDetails = DarwinNotificationDetails( - // Between 0.0 and 1.0 - criticalSoundVolume: 0.5, - // If sound is not specified, the default sound will be used - sound: 'slow_spring_board.aiff', - ); + // Between 0.0 and 1.0 + criticalSoundVolume: 0.5, + // If sound is not specified, the default sound will be used + sound: 'slow_spring_board.aiff', + ); const NotificationDetails notificationDetails = NotificationDetails( iOS: darwinNotificationDetails, macOS: darwinNotificationDetails, @@ -2892,8 +3306,8 @@ Future _showLinuxNotificationWithBodyMarkup() async { Future _showLinuxNotificationWithCategory() async { const LinuxNotificationDetails linuxPlatformChannelSpecifics = LinuxNotificationDetails( - category: LinuxNotificationCategory.emailArrived, - ); + category: LinuxNotificationCategory.emailArrived, + ); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -2909,23 +3323,21 @@ Future _showLinuxNotificationWithByteDataIcon() async { final ByteData assetIcon = await rootBundle.load( 'icons/app_icon_density.png', ); - final image.Image? iconData = image.decodePng( - assetIcon.buffer.asUint8List(), - ); + final image.Image? iconData = image.decodePng(assetIcon.buffer.asUint8List()); final Uint8List iconBytes = iconData!.getBytes(); final LinuxNotificationDetails linuxPlatformChannelSpecifics = LinuxNotificationDetails( - icon: ByteDataLinuxIcon( - LinuxRawIconData( - data: iconBytes, - width: iconData.width, - height: iconData.height, - channels: 4, - // The icon has an alpha channel - hasAlpha: true, - ), - ), - ); + icon: ByteDataLinuxIcon( + LinuxRawIconData( + data: iconBytes, + width: iconData.width, + height: iconData.height, + channels: 4, + // The icon has an alpha channel + hasAlpha: true, + ), + ), + ); final NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -2953,9 +3365,7 @@ Future _showLinuxNotificationWithPathIcon(String path) async { Future _showLinuxNotificationWithThemeIcon() async { final LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - icon: ThemeLinuxIcon('media-eject'), - ); + LinuxNotificationDetails(icon: ThemeLinuxIcon('media-eject')); final NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -2969,9 +3379,7 @@ Future _showLinuxNotificationWithThemeIcon() async { Future _showLinuxNotificationWithThemeSound() async { final LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - sound: ThemeLinuxSound('message-new-email'), - ); + LinuxNotificationDetails(sound: ThemeLinuxSound('message-new-email')); final NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -2985,9 +3393,7 @@ Future _showLinuxNotificationWithThemeSound() async { Future _showLinuxNotificationWithCriticalUrgency() async { const LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - urgency: LinuxNotificationUrgency.critical, - ); + LinuxNotificationDetails(urgency: LinuxNotificationUrgency.critical); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -3002,10 +3408,10 @@ Future _showLinuxNotificationWithCriticalUrgency() async { Future _showLinuxNotificationWithTimeout() async { final LinuxNotificationDetails linuxPlatformChannelSpecifics = LinuxNotificationDetails( - timeout: LinuxNotificationTimeout.fromDuration( - const Duration(seconds: 1), - ), - ); + timeout: LinuxNotificationTimeout.fromDuration( + const Duration(seconds: 1), + ), + ); final NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -3019,9 +3425,7 @@ Future _showLinuxNotificationWithTimeout() async { Future _showLinuxNotificationSuppressSound() async { const LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - suppressSound: true, - ); + LinuxNotificationDetails(suppressSound: true); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -3035,9 +3439,7 @@ Future _showLinuxNotificationSuppressSound() async { Future _showLinuxNotificationTransient() async { const LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - transient: true, - ); + LinuxNotificationDetails(transient: true); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -3051,9 +3453,7 @@ Future _showLinuxNotificationTransient() async { Future _showLinuxNotificationResident() async { const LinuxNotificationDetails linuxPlatformChannelSpecifics = - LinuxNotificationDetails( - resident: true, - ); + LinuxNotificationDetails(resident: true); const NotificationDetails notificationDetails = NotificationDetails( linux: linuxPlatformChannelSpecifics, ); @@ -3082,15 +3482,12 @@ Future _showLinuxNotificationDifferentLocation() async { Future getLinuxCapabilities() => flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - LinuxFlutterLocalNotificationsPlugin>()! + LinuxFlutterLocalNotificationsPlugin + >()! .getCapabilities(); class SecondPage extends StatefulWidget { - const SecondPage( - this.payload, { - this.data, - Key? key, - }) : super(key: key); + const SecondPage(this.payload, {this.data, Key? key}) : super(key: key); static const String routeName = '/secondPage'; @@ -3114,54 +3511,45 @@ class SecondPageState extends State { @override Widget build(BuildContext context) => Scaffold( - appBar: AppBar( - title: const Text('Second Screen'), - ), - body: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text('payload ${_payload ?? ''}'), - Text('data ${_data ?? ''}'), - ElevatedButton( - onPressed: () { - Navigator.pop(context); - }, - child: const Text('Go back!'), - ), - ], + appBar: AppBar(title: const Text('Second Screen')), + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text('payload ${_payload ?? ''}'), + Text('data ${_data ?? ''}'), + ElevatedButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('Go back!'), ), - ), - ); + ], + ), + ), + ); } class _InfoValueString extends StatelessWidget { - const _InfoValueString({ - required this.title, - required this.value, - Key? key, - }) : super(key: key); + const _InfoValueString({required this.title, required this.value, Key? key}) + : super(key: key); final String title; final Object? value; @override Widget build(BuildContext context) => Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), - child: Text.rich( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), + child: Text.rich( + TextSpan( + children: [ TextSpan( - children: [ - TextSpan( - text: '$title ', - style: const TextStyle( - fontWeight: FontWeight.bold, - ), - ), - TextSpan( - text: '$value', - ) - ], + text: '$title ', + style: const TextStyle(fontWeight: FontWeight.bold), ), - ), - ); + TextSpan(text: '$value'), + ], + ), + ), + ); } diff --git a/flutter_local_notifications/example/lib/padded_button.dart b/flutter_local_notifications/example/lib/padded_button.dart index 5867d5e3e..2b29f2e13 100644 --- a/flutter_local_notifications/example/lib/padded_button.dart +++ b/flutter_local_notifications/example/lib/padded_button.dart @@ -12,10 +12,7 @@ class PaddedElevatedButton extends StatelessWidget { @override Widget build(BuildContext context) => Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), - child: ElevatedButton( - onPressed: onPressed, - child: Text(buttonText), - ), - ); + padding: const EdgeInsets.fromLTRB(0, 0, 0, 8), + child: ElevatedButton(onPressed: onPressed, child: Text(buttonText)), + ); } diff --git a/flutter_local_notifications/example/lib/repeating.dart b/flutter_local_notifications/example/lib/repeating.dart index 26ce7d9dc..c15cdd0f8 100644 --- a/flutter_local_notifications/example/lib/repeating.dart +++ b/flutter_local_notifications/example/lib/repeating.dart @@ -6,150 +6,174 @@ import 'padded_button.dart'; import 'plugin.dart'; List examples(BuildContext context) => [ - const Divider(), - const Text( - 'Repeating notifications', - style: TextStyle(fontWeight: FontWeight.bold), - ), - PaddedElevatedButton( - buttonText: 'Repeat notification every minute', - onPressed: () async { - await _repeatNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Repeat notification every 5 minutes', - onPressed: () async { - await _repeatPeriodicallyWithDurationNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule daily 10:00:00 am notification in your ' - 'local time zone', - onPressed: () async { - await _scheduleDailyTenAMNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule daily 10:00:00 am notification in your ' - "local time zone using last year's date", - onPressed: () async { - await _scheduleDailyTenAMLastYearNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule weekly 10:00:00 am notification in your ' - 'local time zone', - onPressed: () async { - await _scheduleWeeklyTenAMNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule weekly Monday 10:00:00 am notification ' - 'in your local time zone', - onPressed: () async { - await _scheduleWeeklyMondayTenAMNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule monthly Monday 10:00:00 am notification in ' - 'your local time zone', - onPressed: () async { - await _scheduleMonthlyMondayTenAMNotification(); - }, - ), - PaddedElevatedButton( - buttonText: 'Schedule yearly Monday 10:00:00 am notification in ' - 'your local time zone', - onPressed: () async { - await _scheduleYearlyMondayTenAMNotification(); - }, - ), - ]; + const Divider(), + const Text( + 'Repeating notifications', + style: TextStyle(fontWeight: FontWeight.bold), + ), + PaddedElevatedButton( + buttonText: 'Repeat notification every minute', + onPressed: () async { + await _repeatNotification(); + }, + ), + PaddedElevatedButton( + buttonText: 'Repeat notification every 5 minutes', + onPressed: () async { + await _repeatPeriodicallyWithDurationNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule daily 10:00:00 am notification in your ' + 'local time zone', + onPressed: () async { + await _scheduleDailyTenAMNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule daily 10:00:00 am notification in your ' + "local time zone using last year's date", + onPressed: () async { + await _scheduleDailyTenAMLastYearNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule weekly 10:00:00 am notification in your ' + 'local time zone', + onPressed: () async { + await _scheduleWeeklyTenAMNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule weekly Monday 10:00:00 am notification ' + 'in your local time zone', + onPressed: () async { + await _scheduleWeeklyMondayTenAMNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule monthly Monday 10:00:00 am notification in ' + 'your local time zone', + onPressed: () async { + await _scheduleMonthlyMondayTenAMNotification(); + }, + ), + PaddedElevatedButton( + buttonText: + 'Schedule yearly Monday 10:00:00 am notification in ' + 'your local time zone', + onPressed: () async { + await _scheduleYearlyMondayTenAMNotification(); + }, + ), +]; /// To test we don't validate past dates when using `matchDateTimeComponents` Future _scheduleDailyTenAMLastYearNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'daily scheduled notification title', - 'daily scheduled notification body', - _nextInstanceOfTenAMLastYear(), - const NotificationDetails( - android: AndroidNotificationDetails( - 'daily notification channel id', 'daily notification channel name', - channelDescription: 'daily notification description'), + 0, + 'daily scheduled notification title', + 'daily scheduled notification body', + _nextInstanceOfTenAMLastYear(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'daily notification channel id', + 'daily notification channel name', + channelDescription: 'daily notification description', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.time); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.time, + ); } Future _scheduleWeeklyTenAMNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'weekly scheduled notification title', - 'weekly scheduled notification body', - _nextInstanceOfTenAM(), - const NotificationDetails( - android: AndroidNotificationDetails('weekly notification channel id', - 'weekly notification channel name', - channelDescription: 'weekly notificationdescription'), + 0, + 'weekly scheduled notification title', + 'weekly scheduled notification body', + _nextInstanceOfTenAM(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'weekly notification channel id', + 'weekly notification channel name', + channelDescription: 'weekly notificationdescription', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime, + ); } Future _scheduleWeeklyMondayTenAMNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'weekly scheduled notification title', - 'weekly scheduled notification body', - _nextInstanceOfMondayTenAM(), - const NotificationDetails( - android: AndroidNotificationDetails('weekly notification channel id', - 'weekly notification channel name', - channelDescription: 'weekly notificationdescription'), + 0, + 'weekly scheduled notification title', + 'weekly scheduled notification body', + _nextInstanceOfMondayTenAM(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'weekly notification channel id', + 'weekly notification channel name', + channelDescription: 'weekly notificationdescription', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime, + ); } Future _scheduleMonthlyMondayTenAMNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'monthly scheduled notification title', - 'monthly scheduled notification body', - _nextInstanceOfMondayTenAM(), - const NotificationDetails( - android: AndroidNotificationDetails('monthly notification channel id', - 'monthly notification channel name', - channelDescription: 'monthly notificationdescription'), + 0, + 'monthly scheduled notification title', + 'monthly scheduled notification body', + _nextInstanceOfMondayTenAM(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'monthly notification channel id', + 'monthly notification channel name', + channelDescription: 'monthly notificationdescription', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dayOfMonthAndTime); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dayOfMonthAndTime, + ); } Future _scheduleYearlyMondayTenAMNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'yearly scheduled notification title', - 'yearly scheduled notification body', - _nextInstanceOfMondayTenAM(), - const NotificationDetails( - android: AndroidNotificationDetails('yearly notification channel id', - 'yearly notification channel name', - channelDescription: 'yearly notification description'), + 0, + 'yearly scheduled notification title', + 'yearly scheduled notification body', + _nextInstanceOfMondayTenAM(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'yearly notification channel id', + 'yearly notification channel name', + channelDescription: 'yearly notification description', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dateAndTime); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dateAndTime, + ); } Future _repeatNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'repeating channel id', 'repeating channel name', - channelDescription: 'repeating description'); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'repeating channel id', + 'repeating channel name', + channelDescription: 'repeating description', + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.periodicallyShow( id++, 'repeating title', @@ -163,10 +187,13 @@ Future _repeatNotification() async { Future _repeatPeriodicallyWithDurationNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'repeating channel id', 'repeating channel name', - channelDescription: 'repeating description'); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); + 'repeating channel id', + 'repeating channel name', + channelDescription: 'repeating description', + ); + const NotificationDetails notificationDetails = NotificationDetails( + android: androidNotificationDetails, + ); await flutterLocalNotificationsPlugin.periodicallyShowWithDuration( id++, 'repeating period title', @@ -179,23 +206,31 @@ Future _repeatPeriodicallyWithDurationNotification() async { Future _scheduleDailyTenAMNotification() async { await flutterLocalNotificationsPlugin.zonedSchedule( - 0, - 'daily scheduled notification title', - 'daily scheduled notification body', - _nextInstanceOfTenAM(), - const NotificationDetails( - android: AndroidNotificationDetails( - 'daily notification channel id', 'daily notification channel name', - channelDescription: 'daily notification description'), + 0, + 'daily scheduled notification title', + 'daily scheduled notification body', + _nextInstanceOfTenAM(), + const NotificationDetails( + android: AndroidNotificationDetails( + 'daily notification channel id', + 'daily notification channel name', + channelDescription: 'daily notification description', ), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.time); + ), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.time, + ); } tz.TZDateTime _nextInstanceOfTenAM() { final tz.TZDateTime now = tz.TZDateTime.now(tz.local); - tz.TZDateTime scheduledDate = - tz.TZDateTime(tz.local, now.year, now.month, now.day, 10); + tz.TZDateTime scheduledDate = tz.TZDateTime( + tz.local, + now.year, + now.month, + now.day, + 10, + ); if (scheduledDate.isBefore(now)) { scheduledDate = scheduledDate.add(const Duration(days: 1)); } diff --git a/flutter_local_notifications/example/lib/windows.dart b/flutter_local_notifications/example/lib/windows.dart index 025c8b186..f297a93fe 100644 --- a/flutter_local_notifications/example/lib/windows.dart +++ b/flutter_local_notifications/example/lib/windows.dart @@ -8,10 +8,10 @@ import 'plugin.dart'; const WindowsInitializationSettings initSettings = WindowsInitializationSettings( - appName: 'Flutter Local Notifications Example', - appUserModelId: 'Com.Dexterous.FlutterLocalNotificationsExample', - guid: 'd49b0314-ee7a-4626-bf79-97cdb8a991bb', -); + appName: 'Flutter Local Notifications Example', + appUserModelId: 'Com.Dexterous.FlutterLocalNotificationsExample', + guid: 'd49b0314-ee7a-4626-bf79-97cdb8a991bb', + ); class _WindowsXmlBuilder extends StatefulWidget { @override @@ -21,12 +21,14 @@ class _WindowsXmlBuilder extends StatefulWidget { class _WindowsXmlBuilderState extends State<_WindowsXmlBuilder> { final TextEditingController xmlController = TextEditingController(); final Map bindings = { - 'message': 'Hello, World!' + 'message': 'Hello, World!', }; final FlutterLocalNotificationsWindows? plugin = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + FlutterLocalNotificationsWindows + >(); String get xml => xmlController.text; @@ -41,107 +43,107 @@ class _WindowsXmlBuilderState extends State<_WindowsXmlBuilder> { @override Widget build(BuildContext context) => SizedBox( - width: 500, - child: ExpansionTile( - title: const Text('Click to expand raw XML'), - children: [ - TextField( - maxLines: 20, - style: const TextStyle(fontFamily: 'RobotoMono'), - controller: xmlController, - onSubmitted: (_) => onPressed, - decoration: InputDecoration( - hintText: 'Enter the raw xml', - errorText: isValid ? null : 'Invalid XML', - helperText: 'Bindings: {message} --> Hello, World!', - constraints: - const BoxConstraints.tightFor(width: 600, height: 480), - suffixIcon: IconButton( - icon: const Icon(Icons.clear), - onPressed: () => xmlController.clear(), - ), - ), - ), - const SizedBox(height: 8), - PaddedElevatedButton( - buttonText: 'Show notification with raw XML', - onPressed: onPressed, - ), - ]), - ); + width: 500, + child: ExpansionTile( + title: const Text('Click to expand raw XML'), + children: [ + TextField( + maxLines: 20, + style: const TextStyle(fontFamily: 'RobotoMono'), + controller: xmlController, + onSubmitted: (_) => onPressed, + decoration: InputDecoration( + hintText: 'Enter the raw xml', + errorText: isValid ? null : 'Invalid XML', + helperText: 'Bindings: {message} --> Hello, World!', + constraints: const BoxConstraints.tightFor(width: 600, height: 480), + suffixIcon: IconButton( + icon: const Icon(Icons.clear), + onPressed: () => xmlController.clear(), + ), + ), + ), + const SizedBox(height: 8), + PaddedElevatedButton( + buttonText: 'Show notification with raw XML', + onPressed: onPressed, + ), + ], + ), + ); } List examples() => [ - const Text( - 'Windows-specific examples', - style: TextStyle(fontWeight: FontWeight.bold), - ), - if (MsixUtils.hasPackageIdentity()) - const Text('Running as an MSIX, all features are available') - else - const Text('Running as an EXE, some features are not available'), - PaddedElevatedButton( - buttonText: 'Show short and long notifications notification', - onPressed: () async { - await _showWindowsNotificationWithDuration(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show different scenarios', - onPressed: () async { - await _showWindowsNotificationWithScenarios(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with some detail', - onPressed: () async { - await _showWindowsNotificationWithDetails(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with image', - onPressed: () async { - await _showWindowsNotificationWithImages(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with columns', - onPressed: () async { - await _showWindowsNotificationWithGroups(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with progress bar', - onPressed: () async { - await _showWindowsNotificationWithProgress(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications with dynamic content', - onPressed: () async { - await _showWindowsNotificationWithDynamic(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with activation', - onPressed: () async { - await _showWindowsNotificationWithActivation(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notification with button styles', - onPressed: () async { - await _showWindowsNotificationWithButtonStyle(); - }, - ), - PaddedElevatedButton( - buttonText: 'Show notifications in a group', - onPressed: () async { - await _showWindowsNotificationWithHeader(); - }, - ), - _WindowsXmlBuilder(), - ]; + const Text( + 'Windows-specific examples', + style: TextStyle(fontWeight: FontWeight.bold), + ), + if (MsixUtils.hasPackageIdentity()) + const Text('Running as an MSIX, all features are available') + else + const Text('Running as an EXE, some features are not available'), + PaddedElevatedButton( + buttonText: 'Show short and long notifications notification', + onPressed: () async { + await _showWindowsNotificationWithDuration(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show different scenarios', + onPressed: () async { + await _showWindowsNotificationWithScenarios(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with some detail', + onPressed: () async { + await _showWindowsNotificationWithDetails(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with image', + onPressed: () async { + await _showWindowsNotificationWithImages(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with columns', + onPressed: () async { + await _showWindowsNotificationWithGroups(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with progress bar', + onPressed: () async { + await _showWindowsNotificationWithProgress(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications with dynamic content', + onPressed: () async { + await _showWindowsNotificationWithDynamic(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with activation', + onPressed: () async { + await _showWindowsNotificationWithActivation(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notification with button styles', + onPressed: () async { + await _showWindowsNotificationWithButtonStyle(); + }, + ), + PaddedElevatedButton( + buttonText: 'Show notifications in a group', + onPressed: () async { + await _showWindowsNotificationWithHeader(); + }, + ), + _WindowsXmlBuilder(), +]; Future _showWindowsNotificationWithDuration() async { await flutterLocalNotificationsPlugin.show( @@ -150,7 +152,8 @@ Future _showWindowsNotificationWithDuration() async { 'This will last about 7 seconds', const NotificationDetails( windows: WindowsNotificationDetails( - duration: WindowsNotificationDuration.short), + duration: WindowsNotificationDuration.short, + ), ), ); await flutterLocalNotificationsPlugin.show( @@ -159,7 +162,8 @@ Future _showWindowsNotificationWithDuration() async { 'This will last about 25 seconds', const NotificationDetails( windows: WindowsNotificationDetails( - duration: WindowsNotificationDuration.long), + duration: WindowsNotificationDuration.long, + ), ), ); } @@ -173,7 +177,7 @@ Future _showWindowsNotificationWithScenarios() async { windows: WindowsNotificationDetails( scenario: WindowsNotificationScenario.alarm, actions: [ - WindowsAction(content: 'Button', arguments: 'button') + WindowsAction(content: 'Button', arguments: 'button'), ], ), ), @@ -186,7 +190,7 @@ Future _showWindowsNotificationWithScenarios() async { windows: WindowsNotificationDetails( scenario: WindowsNotificationScenario.incomingCall, actions: [ - WindowsAction(content: 'Button', arguments: 'button') + WindowsAction(content: 'Button', arguments: 'button'), ], ), ), @@ -197,10 +201,11 @@ Future _showWindowsNotificationWithScenarios() async { null, const NotificationDetails( windows: WindowsNotificationDetails( - scenario: WindowsNotificationScenario.reminder, - actions: [ - WindowsAction(content: 'Button', arguments: 'button') - ]), + scenario: WindowsNotificationScenario.reminder, + actions: [ + WindowsAction(content: 'Button', arguments: 'button'), + ], + ), ), ); await flutterLocalNotificationsPlugin.show( @@ -209,10 +214,11 @@ Future _showWindowsNotificationWithScenarios() async { null, const NotificationDetails( windows: WindowsNotificationDetails( - scenario: WindowsNotificationScenario.urgent, - actions: [ - WindowsAction(content: 'Button', arguments: 'button') - ]), + scenario: WindowsNotificationScenario.urgent, + actions: [ + WindowsAction(content: 'Button', arguments: 'button'), + ], + ), ), ); } @@ -225,28 +231,29 @@ Future _showWindowsNotificationWithDetails() => NotificationDetails( windows: WindowsNotificationDetails( subtitle: 'This is the subtitle', - timestamp: - DateTime.now().subtract(const Duration(hours: 2, minutes: 5)), + timestamp: DateTime.now().subtract( + const Duration(hours: 2, minutes: 5), + ), ), ), ); -Future _showWindowsNotificationWithImages() => - flutterLocalNotificationsPlugin.show( - id++, - 'This notification has an image', - 'You can show images from assets or the network. See the columns example as well.', - NotificationDetails( - windows: WindowsNotificationDetails( - images: [ - WindowsImage( - WindowsImage.getAssetUri('icons/4.0x/app_icon_density.png'), - altText: 'A beautiful image', - ), - ], +Future +_showWindowsNotificationWithImages() => flutterLocalNotificationsPlugin.show( + id++, + 'This notification has an image', + 'You can show images from assets or the network. See the columns example as well.', + NotificationDetails( + windows: WindowsNotificationDetails( + images: [ + WindowsImage( + WindowsImage.getAssetUri('icons/4.0x/app_icon_density.png'), + altText: 'A beautiful image', ), - ), - ); + ], + ), + ), +); Future _showWindowsNotificationWithGroups() => flutterLocalNotificationsPlugin.show( @@ -283,16 +290,22 @@ Future _showWindowsNotificationWithGroups() => Future _showWindowsNotificationWithProgress() async { final WindowsProgressBar fastProgress = WindowsProgressBar( - id: 'fast-progress', status: 'Updating quickly...', value: 0); + id: 'fast-progress', + status: 'Updating quickly...', + value: 0, + ); final WindowsProgressBar slowProgress = WindowsProgressBar( - id: 'slow-progress', - status: 'Updating slowly...', - value: 0, - label: '0 / 10'); + id: 'slow-progress', + status: 'Updating slowly...', + value: 0, + label: '0 / 10', + ); final int notificationId = id++; final FlutterLocalNotificationsWindows? windows = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + FlutterLocalNotificationsWindows + >(); await flutterLocalNotificationsPlugin.show( notificationId, 'This notification has progress bars', @@ -313,11 +326,12 @@ Future _showWindowsNotificationWithProgress() async { value: 0.75, ), WindowsProgressBar( - id: 'discrete', - title: 'This has discrete progress', - status: 'Syncing...', - value: 0.75, - label: '9/12 complete'), + id: 'discrete', + title: 'This has discrete progress', + status: 'Syncing...', + value: 0.75, + label: '9/12 complete', + ), fastProgress, slowProgress, ], @@ -337,9 +351,13 @@ Future _showWindowsNotificationWithProgress() async { count = count.clamp(0, 50); slowProgress.label = '$count / 50'; await windows?.updateProgressBar( - notificationId: notificationId, progressBar: fastProgress); + notificationId: notificationId, + progressBar: fastProgress, + ); await windows?.updateProgressBar( - notificationId: notificationId, progressBar: slowProgress); + notificationId: notificationId, + progressBar: slowProgress, + ); }); } @@ -347,22 +365,22 @@ Future _showWindowsNotificationWithDynamic() async { final DateTime start = DateTime.now(); final int notificationId = id++; final FlutterLocalNotificationsWindows? windows = - flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>(); + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + FlutterLocalNotificationsWindows + >(); await flutterLocalNotificationsPlugin.show( notificationId, 'Dynamic content', 'This notification will be updated from Dart code', const NotificationDetails( - windows: WindowsNotificationDetails( - subtitle: '{stopwatch}', - ), + windows: WindowsNotificationDetails(subtitle: '{stopwatch}'), ), ); Map getBindings() => { - 'stopwatch': - 'Elapsed time: ${DateTime.now().difference(start).inSeconds} seconds', - }; + 'stopwatch': + 'Elapsed time: ${DateTime.now().difference(start).inSeconds} seconds', + }; await windows?.updateBindings(id: notificationId, bindings: getBindings()); Timer.periodic(const Duration(seconds: 1), (Timer timer) async { if (timer.tick > 10) { diff --git a/flutter_local_notifications/lib/src/callback_dispatcher.dart b/flutter_local_notifications/lib/src/callback_dispatcher.dart index 7402efa01..111489c26 100644 --- a/flutter_local_notifications/lib/src/callback_dispatcher.dart +++ b/flutter_local_notifications/lib/src/callback_dispatcher.dart @@ -9,43 +9,49 @@ import 'package:flutter_local_notifications_platform_interface/flutter_local_not void callbackDispatcher() { WidgetsFlutterBinding.ensureInitialized(); - const EventChannel backgroundChannel = - EventChannel('dexterous.com/flutter/local_notifications/actions'); + const EventChannel backgroundChannel = EventChannel( + 'dexterous.com/flutter/local_notifications/actions', + ); - const MethodChannel channel = - MethodChannel('dexterous.com/flutter/local_notifications'); + const MethodChannel channel = MethodChannel( + 'dexterous.com/flutter/local_notifications', + ); channel.invokeMethod('getCallbackHandle').then((int? handle) { final DidReceiveBackgroundNotificationResponseCallback? callback = handle == null - ? null - : PluginUtilities.getCallbackFromHandle( - CallbackHandle.fromRawHandle(handle)) - as DidReceiveBackgroundNotificationResponseCallback?; + ? null + : PluginUtilities.getCallbackFromHandle( + CallbackHandle.fromRawHandle(handle), + ) + as DidReceiveBackgroundNotificationResponseCallback?; backgroundChannel .receiveBroadcastStream() .map>((dynamic event) => event) .map>( - (Map event) => Map.castFrom(event)) + (Map event) => Map.castFrom(event), + ) .listen((Map event) { - final Object notificationId = event['notificationId']; - final int id; - if (notificationId is int) { - id = notificationId; - } else if (notificationId is String) { - id = int.parse(notificationId); - } else { - id = -1; - } - callback?.call(NotificationResponse( - id: id, - actionId: event['actionId'], - input: event['input'], - payload: event['payload'], - notificationResponseType: - NotificationResponseType.selectedNotificationAction, - )); - }); + final Object notificationId = event['notificationId']; + final int id; + if (notificationId is int) { + id = notificationId; + } else if (notificationId is String) { + id = int.parse(notificationId); + } else { + id = -1; + } + callback?.call( + NotificationResponse( + id: id, + actionId: event['actionId'], + input: event['input'], + payload: event['payload'], + notificationResponseType: + NotificationResponseType.selectedNotificationAction, + ), + ); + }); }); } diff --git a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart index 4a9650131..1d909599f 100644 --- a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart +++ b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart @@ -38,12 +38,14 @@ class FlutterLocalNotificationsPlugin { /// argument is of type [AndroidFlutterLocalNotificationsPlugin], this will /// only return a result of that type when running on Android. T? resolvePlatformSpecificImplementation< - T extends FlutterLocalNotificationsPlatform>() { + T extends FlutterLocalNotificationsPlatform + >() { if (T == FlutterLocalNotificationsPlatform) { throw ArgumentError.value( - T, - 'The type argument must be a concrete subclass of ' - 'FlutterLocalNotificationsPlatform'); + T, + 'The type argument must be a concrete subclass of ' + 'FlutterLocalNotificationsPlatform', + ); } if (kIsWeb) { return null; @@ -114,7 +116,7 @@ class FlutterLocalNotificationsPlugin { InitializationSettings initializationSettings, { DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse, DidReceiveBackgroundNotificationResponseCallback? - onDidReceiveBackgroundNotificationResponse, + onDidReceiveBackgroundNotificationResponse, }) async { if (kIsWeb) { return true; @@ -123,67 +125,77 @@ class FlutterLocalNotificationsPlugin { if (defaultTargetPlatform == TargetPlatform.android) { if (initializationSettings.android == null) { throw ArgumentError( - 'Android settings must be set when targeting Android platform.'); + 'Android settings must be set when targeting Android platform.', + ); } return resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.initialize( - initializationSettings.android!, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - onDidReceiveBackgroundNotificationResponse: - onDidReceiveBackgroundNotificationResponse, - ); + initializationSettings.android!, + onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, + onDidReceiveBackgroundNotificationResponse: + onDidReceiveBackgroundNotificationResponse, + ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { if (initializationSettings.iOS == null) { throw ArgumentError( - 'iOS settings must be set when targeting iOS platform.'); + 'iOS settings must be set when targeting iOS platform.', + ); } return await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() + IOSFlutterLocalNotificationsPlugin + >() ?.initialize( - initializationSettings.iOS!, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - onDidReceiveBackgroundNotificationResponse: - onDidReceiveBackgroundNotificationResponse, - ); + initializationSettings.iOS!, + onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, + onDidReceiveBackgroundNotificationResponse: + onDidReceiveBackgroundNotificationResponse, + ); } else if (defaultTargetPlatform == TargetPlatform.macOS) { if (initializationSettings.macOS == null) { throw ArgumentError( - 'macOS settings must be set when targeting macOS platform.'); + 'macOS settings must be set when targeting macOS platform.', + ); } return await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.initialize( - initializationSettings.macOS!, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - ); + initializationSettings.macOS!, + onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, + ); } else if (defaultTargetPlatform == TargetPlatform.linux) { if (initializationSettings.linux == null) { throw ArgumentError( - 'Linux settings must be set when targeting Linux platform.'); + 'Linux settings must be set when targeting Linux platform.', + ); } return await resolvePlatformSpecificImplementation< - LinuxFlutterLocalNotificationsPlugin>() + LinuxFlutterLocalNotificationsPlugin + >() ?.initialize( - initializationSettings.linux!, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - ); + initializationSettings.linux!, + onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, + ); } else if (defaultTargetPlatform == TargetPlatform.windows) { if (initializationSettings.windows == null) { throw ArgumentError( - 'Windows settings must be set when targeting Windows platform.'); + 'Windows settings must be set when targeting Windows platform.', + ); } return await resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>() + FlutterLocalNotificationsWindows + >() ?.initialize( - initializationSettings.windows!, - onNotificationReceived: onDidReceiveNotificationResponse, - ); + initializationSettings.windows!, + onNotificationReceived: onDidReceiveNotificationResponse, + ); } return true; } @@ -201,25 +213,29 @@ class FlutterLocalNotificationsPlugin { /// versions older than 10.14. This is because there's currently no mechanism /// for plugins to receive information on lifecycle events. Future - getNotificationAppLaunchDetails() async { + getNotificationAppLaunchDetails() async { if (kIsWeb) { return null; } if (defaultTargetPlatform == TargetPlatform.android) { return await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.getNotificationAppLaunchDetails(); } else if (defaultTargetPlatform == TargetPlatform.iOS) { return await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() + IOSFlutterLocalNotificationsPlugin + >() ?.getNotificationAppLaunchDetails(); } else if (defaultTargetPlatform == TargetPlatform.macOS) { return await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.getNotificationAppLaunchDetails(); } else if (defaultTargetPlatform == TargetPlatform.windows) { return await resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>() + FlutterLocalNotificationsWindows + >() ?.getNotificationAppLaunchDetails(); } else { return await FlutterLocalNotificationsPlatform.instance @@ -242,32 +258,59 @@ class FlutterLocalNotificationsPlugin { } if (defaultTargetPlatform == TargetPlatform.android) { await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() - ?.show(id, title, body, - notificationDetails: notificationDetails?.android, - payload: payload); + AndroidFlutterLocalNotificationsPlugin + >() + ?.show( + id, + title, + body, + notificationDetails: notificationDetails?.android, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.show(id, title, body, - notificationDetails: notificationDetails?.iOS, payload: payload); + IOSFlutterLocalNotificationsPlugin + >() + ?.show( + id, + title, + body, + notificationDetails: notificationDetails?.iOS, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() - ?.show(id, title, body, - notificationDetails: notificationDetails?.macOS, - payload: payload); + MacOSFlutterLocalNotificationsPlugin + >() + ?.show( + id, + title, + body, + notificationDetails: notificationDetails?.macOS, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.linux) { await resolvePlatformSpecificImplementation< - LinuxFlutterLocalNotificationsPlugin>() - ?.show(id, title, body, - notificationDetails: notificationDetails?.linux, - payload: payload); + LinuxFlutterLocalNotificationsPlugin + >() + ?.show( + id, + title, + body, + notificationDetails: notificationDetails?.linux, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.windows) { await resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>() - ?.show(id, title, body, - details: notificationDetails?.windows, payload: payload); + FlutterLocalNotificationsWindows + >() + ?.show( + id, + title, + body, + details: notificationDetails?.windows, + payload: payload, + ); } else { await FlutterLocalNotificationsPlatform.instance.show(id, title, body); } @@ -287,7 +330,8 @@ class FlutterLocalNotificationsPlugin { } if (defaultTargetPlatform == TargetPlatform.android) { await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.cancel(id, tag: tag); } else { await FlutterLocalNotificationsPlatform.instance.cancel(id); @@ -357,37 +401,56 @@ class FlutterLocalNotificationsPlugin { } if (defaultTargetPlatform == TargetPlatform.android) { await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .zonedSchedule( - id, title, body, scheduledDate, notificationDetails.android, - payload: payload, - scheduleMode: androidScheduleMode, - matchDateTimeComponents: matchDateTimeComponents); + id, + title, + body, + scheduledDate, + notificationDetails.android, + payload: payload, + scheduleMode: androidScheduleMode, + matchDateTimeComponents: matchDateTimeComponents, + ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() + IOSFlutterLocalNotificationsPlugin + >() ?.zonedSchedule( - id, title, body, scheduledDate, notificationDetails.iOS, - payload: payload, - matchDateTimeComponents: matchDateTimeComponents); + id, + title, + body, + scheduledDate, + notificationDetails.iOS, + payload: payload, + matchDateTimeComponents: matchDateTimeComponents, + ); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.zonedSchedule( - id, title, body, scheduledDate, notificationDetails.macOS, - payload: payload, - matchDateTimeComponents: matchDateTimeComponents); + id, + title, + body, + scheduledDate, + notificationDetails.macOS, + payload: payload, + matchDateTimeComponents: matchDateTimeComponents, + ); } else if (defaultTargetPlatform == TargetPlatform.windows) { await resolvePlatformSpecificImplementation< - FlutterLocalNotificationsWindows>() + FlutterLocalNotificationsWindows + >() ?.zonedSchedule( - id, - title, - body, - scheduledDate, - notificationDetails.windows, - payload: payload, - ); + id, + title, + body, + scheduledDate, + notificationDetails.windows, + payload: payload, + ); } else { throw UnimplementedError('zonedSchedule() has not been implemented'); } @@ -416,26 +479,50 @@ class FlutterLocalNotificationsPlugin { } if (defaultTargetPlatform == TargetPlatform.android) { await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() - ?.periodicallyShow(id, title, body, repeatInterval, - notificationDetails: notificationDetails.android, - payload: payload, - scheduleMode: androidScheduleMode); + AndroidFlutterLocalNotificationsPlugin + >() + ?.periodicallyShow( + id, + title, + body, + repeatInterval, + notificationDetails: notificationDetails.android, + payload: payload, + scheduleMode: androidScheduleMode, + ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() - ?.periodicallyShow(id, title, body, repeatInterval, - notificationDetails: notificationDetails.iOS, payload: payload); + IOSFlutterLocalNotificationsPlugin + >() + ?.periodicallyShow( + id, + title, + body, + repeatInterval, + notificationDetails: notificationDetails.iOS, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() - ?.periodicallyShow(id, title, body, repeatInterval, - notificationDetails: notificationDetails.macOS, payload: payload); + MacOSFlutterLocalNotificationsPlugin + >() + ?.periodicallyShow( + id, + title, + body, + repeatInterval, + notificationDetails: notificationDetails.macOS, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.windows) { throw UnsupportedError('Notifications do not repeat on Windows'); } else { - await FlutterLocalNotificationsPlatform.instance - .periodicallyShow(id, title, body, repeatInterval); + await FlutterLocalNotificationsPlatform.instance.periodicallyShow( + id, + title, + body, + repeatInterval, + ); } } @@ -463,28 +550,49 @@ class FlutterLocalNotificationsPlugin { } if (defaultTargetPlatform == TargetPlatform.android) { await resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() + AndroidFlutterLocalNotificationsPlugin + >() ?.periodicallyShowWithDuration( - id, title, body, repeatDurationInterval, - notificationDetails: notificationDetails.android, - payload: payload, - scheduleMode: androidScheduleMode); + id, + title, + body, + repeatDurationInterval, + notificationDetails: notificationDetails.android, + payload: payload, + scheduleMode: androidScheduleMode, + ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { await resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>() + IOSFlutterLocalNotificationsPlugin + >() ?.periodicallyShowWithDuration( - id, title, body, repeatDurationInterval, - notificationDetails: notificationDetails.iOS, payload: payload); + id, + title, + body, + repeatDurationInterval, + notificationDetails: notificationDetails.iOS, + payload: payload, + ); } else if (defaultTargetPlatform == TargetPlatform.macOS) { await resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.periodicallyShowWithDuration( - id, title, body, repeatDurationInterval, - notificationDetails: notificationDetails.macOS, payload: payload); + id, + title, + body, + repeatDurationInterval, + notificationDetails: notificationDetails.macOS, + payload: payload, + ); } else { await FlutterLocalNotificationsPlatform.instance .periodicallyShowWithDuration( - id, title, body, repeatDurationInterval); + id, + title, + body, + repeatDurationInterval, + ); } } diff --git a/flutter_local_notifications/lib/src/helpers.dart b/flutter_local_notifications/lib/src/helpers.dart index cb09dbfbc..2eb54dc00 100644 --- a/flutter_local_notifications/lib/src/helpers.dart +++ b/flutter_local_notifications/lib/src/helpers.dart @@ -14,6 +14,9 @@ void validateDateIsInTheFuture( } if (scheduledDate.isBefore(clock.now())) { throw ArgumentError.value( - scheduledDate, 'scheduledDate', 'Must be a date in the future'); + scheduledDate, + 'scheduledDate', + 'Must be a date in the future', + ); } } diff --git a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart index 5fd1bba90..564038674 100644 --- a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart +++ b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart @@ -27,8 +27,9 @@ import 'platform_specifics/darwin/notification_enabled_options.dart'; import 'types.dart'; import 'tz_datetime_mapper.dart'; -const MethodChannel _channel = - MethodChannel('dexterous.com/flutter/local_notifications'); +const MethodChannel _channel = MethodChannel( + 'dexterous.com/flutter/local_notifications', +); /// An implementation of a local notifications platform using method channels. class MethodChannelFlutterLocalNotificationsPlugin @@ -49,13 +50,14 @@ class MethodChannelFlutterLocalNotificationsPlugin @override Future - getNotificationAppLaunchDetails() async { - final Map? result = - await _channel.invokeMethod('getNotificationAppLaunchDetails'); + getNotificationAppLaunchDetails() async { + final Map? result = await _channel.invokeMethod( + 'getNotificationAppLaunchDetails', + ); final Map? notificationResponse = result != null && result.containsKey('notificationResponse') - ? result['notificationResponse'] - : null; + ? result['notificationResponse'] + : null; return result == null ? null : NotificationAppLaunchDetails( @@ -66,8 +68,8 @@ class MethodChannelFlutterLocalNotificationsPlugin id: notificationResponse['notificationId'], actionId: notificationResponse['actionId'], input: notificationResponse['input'], - notificationResponseType: NotificationResponseType.values[ - notificationResponse['notificationResponseType']], + notificationResponseType: NotificationResponseType + .values[notificationResponse['notificationResponseType']], payload: notificationResponse.containsKey('payload') ? notificationResponse['payload'] : null, @@ -80,32 +82,40 @@ class MethodChannelFlutterLocalNotificationsPlugin @override Future> pendingNotificationRequests() async { - final List>? pendingNotifications = - await _channel.invokeListMethod('pendingNotificationRequests'); + final List>? pendingNotifications = await _channel + .invokeListMethod('pendingNotificationRequests'); return pendingNotifications // ignore: always_specify_types - ?.map((p) => PendingNotificationRequest( - p['id'], p['title'], p['body'], p['payload'])) + ?.map( + (p) => PendingNotificationRequest( + p['id'], + p['title'], + p['body'], + p['payload'], + ), + ) .toList() ?? []; } @override Future> getActiveNotifications() async { - final List>? activeNotifications = - await _channel.invokeListMethod('getActiveNotifications'); + final List>? activeNotifications = await _channel + .invokeListMethod('getActiveNotifications'); return activeNotifications // ignore: always_specify_types - ?.map((p) => ActiveNotification( - id: p['id'], - channelId: p['channelId'], - groupKey: p['groupKey'], - tag: p['tag'], - title: p['title'], - body: p['body'], - payload: p['payload'], - bigText: p['bigText'], - )) + ?.map( + (p) => ActiveNotification( + id: p['id'], + channelId: p['channelId'], + groupKey: p['groupKey'], + tag: p['tag'], + title: p['title'], + body: p['body'], + payload: p['payload'], + bigText: p['bigText'], + ), + ) .toList() ?? []; } @@ -142,7 +152,7 @@ class AndroidFlutterLocalNotificationsPlugin AndroidInitializationSettings initializationSettings, { DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse, DidReceiveBackgroundNotificationResponseCallback? - onDidReceiveBackgroundNotificationResponse, + onDidReceiveBackgroundNotificationResponse, }) async { _onDidReceiveNotificationResponse = onDidReceiveNotificationResponse; _channel.setMethodCallHandler(_handleMethod); @@ -150,7 +160,9 @@ class AndroidFlutterLocalNotificationsPlugin final Map arguments = initializationSettings.toMap(); _evaluateBackgroundNotificationCallback( - onDidReceiveBackgroundNotificationResponse, arguments); + onDidReceiveBackgroundNotificationResponse, + arguments, + ); return await _channel.invokeMethod('initialize', arguments); } @@ -244,20 +256,19 @@ class AndroidFlutterLocalNotificationsPlugin validateId(id); validateDateIsInTheFuture(scheduledDate, matchDateTimeComponents); - await _channel.invokeMethod( - 'zonedSchedule', - { - 'id': id, - 'title': title, - 'body': body, - 'platformSpecifics': - _buildPlatformSpecifics(notificationDetails, scheduleMode), - 'payload': payload ?? '', - ...scheduledDate.toMap(), - if (matchDateTimeComponents != null) - 'matchDateTimeComponents': matchDateTimeComponents.index - }, - ); + await _channel.invokeMethod('zonedSchedule', { + 'id': id, + 'title': title, + 'body': body, + 'platformSpecifics': _buildPlatformSpecifics( + notificationDetails, + scheduleMode, + ), + 'payload': payload ?? '', + ...scheduledDate.toMap(), + if (matchDateTimeComponents != null) + 'matchDateTimeComponents': matchDateTimeComponents.index, + }); } /// Starts an Android foreground service with the given notification. @@ -309,19 +320,29 @@ class AndroidFlutterLocalNotificationsPlugin /// Note that `foregroundServiceType` (the parameter in this method) /// must be a subset of the `android:foregroundServiceType` /// defined in your `AndroidManifest.xml` (the one from the section above)! - Future startForegroundService(int id, String? title, String? body, - {AndroidNotificationDetails? notificationDetails, - String? payload, - AndroidServiceStartType startType = AndroidServiceStartType.startSticky, - Set? foregroundServiceTypes}) { + Future startForegroundService( + int id, + String? title, + String? body, { + AndroidNotificationDetails? notificationDetails, + String? payload, + AndroidServiceStartType startType = AndroidServiceStartType.startSticky, + Set? foregroundServiceTypes, + }) { validateId(id); if (id == 0) { - throw ArgumentError.value(id, 'id', - 'The id of a notification used for an Android foreground service must not be 0!'); // ignore: lines_longer_than_80_chars + throw ArgumentError.value( + id, + 'id', + 'The id of a notification used for an Android foreground service must not be 0!', + ); // ignore: lines_longer_than_80_chars } if (foregroundServiceTypes?.isEmpty ?? false) { - throw ArgumentError.value(foregroundServiceTypes, 'foregroundServiceType', - 'foregroundServiceType may be null but it must never be empty!'); + throw ArgumentError.value( + foregroundServiceTypes, + 'foregroundServiceType', + 'foregroundServiceType may be null but it must never be empty!', + ); } return _channel.invokeMethod('startForegroundService', { 'notificationData': { @@ -334,7 +355,7 @@ class AndroidFlutterLocalNotificationsPlugin 'startType': startType.index, 'foregroundServiceTypes': foregroundServiceTypes ?.map((AndroidServiceForegroundType type) => type.value) - .toList() + .toList(), }); } @@ -358,16 +379,13 @@ class AndroidFlutterLocalNotificationsPlugin String? payload, }) { validateId(id); - return _channel.invokeMethod( - 'show', - { - 'id': id, - 'title': title, - 'body': body, - 'payload': payload ?? '', - 'platformSpecifics': notificationDetails?.toMap(), - }, - ); + return _channel.invokeMethod('show', { + 'id': id, + 'title': title, + 'body': body, + 'payload': payload ?? '', + 'platformSpecifics': notificationDetails?.toMap(), + }); } /// Periodically show a notification using the specified interval. @@ -396,8 +414,10 @@ class AndroidFlutterLocalNotificationsPlugin 'body': body, 'calledAt': clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, - 'platformSpecifics': - _buildPlatformSpecifics(notificationDetails, scheduleMode), + 'platformSpecifics': _buildPlatformSpecifics( + notificationDetails, + scheduleMode, + ), 'payload': payload ?? '', }); } @@ -416,25 +436,26 @@ class AndroidFlutterLocalNotificationsPlugin validateRepeatDurationInterval(repeatDurationInterval); await _channel .invokeMethod('periodicallyShowWithDuration', { - 'id': id, - 'title': title, - 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, - 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, - 'platformSpecifics': - _buildPlatformSpecifics(notificationDetails, scheduleMode), - 'payload': payload ?? '', - }); + 'id': id, + 'title': title, + 'body': body, + 'calledAt': clock.now().millisecondsSinceEpoch, + 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, + 'platformSpecifics': _buildPlatformSpecifics( + notificationDetails, + scheduleMode, + ), + 'payload': payload ?? '', + }); } Map _buildPlatformSpecifics( AndroidNotificationDetails? notificationDetails, AndroidScheduleMode scheduleMode, - ) => - { - if (notificationDetails != null) ...notificationDetails.toMap(), - 'scheduleMode': scheduleMode.name, - }; + ) => { + if (notificationDetails != null) ...notificationDetails.toMap(), + 'scheduleMode': scheduleMode.name, + }; /// Cancel/remove the notification with the specified id. /// @@ -458,9 +479,11 @@ class AndroidFlutterLocalNotificationsPlugin /// /// This method is only applicable to Android versions 8.0 or newer. Future createNotificationChannelGroup( - AndroidNotificationChannelGroup notificationChannelGroup) => - _channel.invokeMethod( - 'createNotificationChannelGroup', notificationChannelGroup.toMap()); + AndroidNotificationChannelGroup notificationChannelGroup, + ) => _channel.invokeMethod( + 'createNotificationChannelGroup', + notificationChannelGroup.toMap(), + ); /// Deletes the notification channel group with the specified [groupId] /// as well as all of the channels belonging to the group. @@ -473,9 +496,11 @@ class AndroidFlutterLocalNotificationsPlugin /// /// This method is only applicable to Android versions 8.0 or newer. Future createNotificationChannel( - AndroidNotificationChannel notificationChannel) => - _channel.invokeMethod( - 'createNotificationChannel', notificationChannel.toMap()); + AndroidNotificationChannel notificationChannel, + ) => _channel.invokeMethod( + 'createNotificationChannel', + notificationChannel.toMap(), + ); /// Deletes the notification channel with the specified [channelId]. /// @@ -496,11 +521,10 @@ class AndroidFlutterLocalNotificationsPlugin int id, { String? tag, }) async { - final Map? m = await _channel - .invokeMethod('getActiveNotificationMessagingStyle', { - 'id': id, - 'tag': tag, - }); + final Map? m = await _channel.invokeMethod( + 'getActiveNotificationMessagingStyle', + {'id': id, 'tag': tag}, + ); if (m == null) { return null; } @@ -530,12 +554,12 @@ class AndroidFlutterLocalNotificationsPlugin } Message _messageFromMap(Map m) => Message( - m['text'], - DateTime.fromMillisecondsSinceEpoch(m['timestamp']), - _personFromMap(m['person']), - dataMimeType: m['dataMimeType'], - dataUri: m['dataUri'], - ); + m['text'], + DateTime.fromMillisecondsSinceEpoch(m['timestamp']), + _personFromMap(m['person']), + dataMimeType: m['dataMimeType'], + dataUri: m['dataUri'], + ); AndroidIcon? _iconFromMap(Map? m) { if (m == null) { @@ -556,33 +580,35 @@ class AndroidFlutterLocalNotificationsPlugin /// This method is only applicable on Android 8.0 or newer. On older versions, /// it will return an empty list. Future?> getNotificationChannels() async { - final List>? notificationChannels = - await _channel.invokeListMethod('getNotificationChannels'); + final List>? notificationChannels = await _channel + .invokeListMethod('getNotificationChannels'); return notificationChannels // ignore: always_specify_types - ?.map((a) => AndroidNotificationChannel( - a['id'], - a['name'], - description: a['description'], - groupId: a['groupId'], - showBadge: a['showBadge'], - importance: Importance.values - // ignore: always_specify_types - .firstWhere((i) => i.value == a['importance']), - bypassDnd: a['bypassDnd'], - playSound: a['playSound'], - sound: _getNotificationChannelSound(a), - enableLights: a['enableLights'], - enableVibration: a['enableVibration'], - vibrationPattern: a['vibrationPattern'], - ledColor: Color(a['ledColor']), - audioAttributesUsage: AudioAttributesUsage.values.firstWhere( + ?.map( + (a) => AndroidNotificationChannel( + a['id'], + a['name'], + description: a['description'], + groupId: a['groupId'], + showBadge: a['showBadge'], + importance: Importance.values // ignore: always_specify_types - (e) => e.value == a['audioAttributesUsage'], - orElse: () => AudioAttributesUsage.notification, - ), - )) + .firstWhere((i) => i.value == a['importance']), + bypassDnd: a['bypassDnd'], + playSound: a['playSound'], + sound: _getNotificationChannelSound(a), + enableLights: a['enableLights'], + enableVibration: a['enableVibration'], + vibrationPattern: a['vibrationPattern'], + ledColor: Color(a['ledColor']), + audioAttributesUsage: AudioAttributesUsage.values.firstWhere( + // ignore: always_specify_types + (e) => e.value == a['audioAttributesUsage'], + orElse: () => AudioAttributesUsage.notification, + ), + ), + ) .toList(); } @@ -603,7 +629,8 @@ class AndroidFlutterLocalNotificationsPlugin await _channel.invokeMethod('canScheduleExactNotifications'); AndroidNotificationSound? _getNotificationChannelSound( - Map channelMap) { + Map channelMap, + ) { final int? soundSourceIndex = channelMap['soundSource']; AndroidNotificationSound? sound; if (soundSourceIndex != null) { @@ -679,7 +706,7 @@ class IOSFlutterLocalNotificationsPlugin DarwinInitializationSettings initializationSettings, { DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse, DidReceiveBackgroundNotificationResponseCallback? - onDidReceiveBackgroundNotificationResponse, + onDidReceiveBackgroundNotificationResponse, }) async { _onDidReceiveNotificationResponse = onDidReceiveNotificationResponse; _channel.setMethodCallHandler(_handleMethod); @@ -687,7 +714,9 @@ class IOSFlutterLocalNotificationsPlugin final Map arguments = initializationSettings.toMap(); _evaluateBackgroundNotificationCallback( - onDidReceiveBackgroundNotificationResponse, arguments); + onDidReceiveBackgroundNotificationResponse, + arguments, + ); return await _channel.invokeMethod('initialize', arguments); } @@ -701,38 +730,36 @@ class IOSFlutterLocalNotificationsPlugin bool provisional = false, bool critical = false, bool providesAppNotificationSettings = false, - }) => - _channel.invokeMethod('requestPermissions', { - 'sound': sound, - 'alert': alert, - 'badge': badge, - 'provisional': provisional, - 'critical': critical, - 'providesAppNotificationSettings': providesAppNotificationSettings, - }); + }) => _channel.invokeMethod('requestPermissions', { + 'sound': sound, + 'alert': alert, + 'badge': badge, + 'provisional': provisional, + 'critical': critical, + 'providesAppNotificationSettings': providesAppNotificationSettings, + }); /// Returns whether the app can post notifications and what kind of. /// /// See [NotificationsEnabledOptions] for more info. - Future checkPermissions() => - _channel.invokeMethod?>('checkPermissions').then( - (Map? dict) { - if (dict == null) { - return null; - } - - return NotificationsEnabledOptions( - isEnabled: dict['isEnabled'] ?? false, - isAlertEnabled: dict['isAlertEnabled'] ?? false, - isBadgeEnabled: dict['isBadgeEnabled'] ?? false, - isSoundEnabled: dict['isSoundEnabled'] ?? false, - isProvisionalEnabled: dict['isProvisionalEnabled'] ?? false, - isCriticalEnabled: dict['isCriticalEnabled'] ?? false, - isProvidesAppNotificationSettingsEnabled: - dict['isProvidesAppNotificationSettingsEnabled'] ?? false, - ); - }, - ); + Future checkPermissions() => _channel + .invokeMethod?>('checkPermissions') + .then((Map? dict) { + if (dict == null) { + return null; + } + + return NotificationsEnabledOptions( + isEnabled: dict['isEnabled'] ?? false, + isAlertEnabled: dict['isAlertEnabled'] ?? false, + isBadgeEnabled: dict['isBadgeEnabled'] ?? false, + isSoundEnabled: dict['isSoundEnabled'] ?? false, + isProvisionalEnabled: dict['isProvisionalEnabled'] ?? false, + isCriticalEnabled: dict['isCriticalEnabled'] ?? false, + isProvidesAppNotificationSettingsEnabled: + dict['isProvidesAppNotificationSettingsEnabled'] ?? false, + ); + }); /// Schedules a notification to be shown at the specified time in the /// future in a specific time zone. @@ -750,20 +777,23 @@ class IOSFlutterLocalNotificationsPlugin final Map serializedPlatformSpecifics = notificationDetails?.toMap() ?? {}; await _channel.invokeMethod( - 'zonedSchedule', - { + 'zonedSchedule', + { 'id': id, 'title': title, 'body': body, 'platformSpecifics': serializedPlatformSpecifics, 'payload': payload ?? '', } - ..addAll(scheduledDate.toMap()) - ..addAll(matchDateTimeComponents == null + ..addAll(scheduledDate.toMap()) + ..addAll( + matchDateTimeComponents == null ? {} : { - 'matchDateTimeComponents': matchDateTimeComponents.index - })); + 'matchDateTimeComponents': matchDateTimeComponents.index, + }, + ), + ); } @override @@ -775,16 +805,13 @@ class IOSFlutterLocalNotificationsPlugin String? payload, }) { validateId(id); - return _channel.invokeMethod( - 'show', - { - 'id': id, - 'title': title, - 'body': body, - 'payload': payload ?? '', - 'platformSpecifics': notificationDetails?.toMap(), - }, - ); + return _channel.invokeMethod('show', { + 'id': id, + 'title': title, + 'body': body, + 'payload': payload ?? '', + 'platformSpecifics': notificationDetails?.toMap(), + }); } @override @@ -804,7 +831,7 @@ class IOSFlutterLocalNotificationsPlugin 'calledAt': clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, 'platformSpecifics': notificationDetails?.toMap(), - 'payload': payload ?? '' + 'payload': payload ?? '', }); } @@ -821,14 +848,14 @@ class IOSFlutterLocalNotificationsPlugin validateRepeatDurationInterval(repeatDurationInterval); await _channel .invokeMethod('periodicallyShowWithDuration', { - 'id': id, - 'title': title, - 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, - 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, - 'platformSpecifics': notificationDetails?.toMap(), - 'payload': payload ?? '' - }); + 'id': id, + 'title': title, + 'body': body, + 'calledAt': clock.now().millisecondsSinceEpoch, + 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, + 'platformSpecifics': notificationDetails?.toMap(), + 'payload': payload ?? '', + }); } Future _handleMethod(MethodCall call) async { @@ -888,7 +915,9 @@ class MacOSFlutterLocalNotificationsPlugin _onDidReceiveNotificationResponse = onDidReceiveNotificationResponse; _channel.setMethodCallHandler(_handleMethod); return await _channel.invokeMethod( - 'initialize', initializationSettings.toMap()); + 'initialize', + initializationSettings.toMap(), + ); } /// Requests the specified permission(s) from user and returns current @@ -900,22 +929,21 @@ class MacOSFlutterLocalNotificationsPlugin bool provisional = false, bool critical = false, bool providesAppNotificationSettings = false, - }) => - _channel.invokeMethod('requestPermissions', { - 'sound': sound, - 'alert': alert, - 'badge': badge, - 'provisional': provisional, - 'critical': critical, - 'providesAppNotificationSettings': providesAppNotificationSettings, - }); + }) => _channel.invokeMethod('requestPermissions', { + 'sound': sound, + 'alert': alert, + 'badge': badge, + 'provisional': provisional, + 'critical': critical, + 'providesAppNotificationSettings': providesAppNotificationSettings, + }); /// Returns whether the app can post notifications and what kind of. /// /// See [NotificationsEnabledOptions] for more info. Future checkPermissions() => _channel - .invokeMethod>('checkPermissions') - .then((Map? dict) { + .invokeMethod>('checkPermissions') + .then((Map? dict) { if (dict == null) { return null; } @@ -948,20 +976,23 @@ class MacOSFlutterLocalNotificationsPlugin final Map serializedPlatformSpecifics = notificationDetails?.toMap() ?? {}; await _channel.invokeMethod( - 'zonedSchedule', - { + 'zonedSchedule', + { 'id': id, 'title': title, 'body': body, 'platformSpecifics': serializedPlatformSpecifics, 'payload': payload ?? '', } - ..addAll(scheduledDate.toMap()) - ..addAll(matchDateTimeComponents == null + ..addAll(scheduledDate.toMap()) + ..addAll( + matchDateTimeComponents == null ? {} : { - 'matchDateTimeComponents': matchDateTimeComponents.index - })); + 'matchDateTimeComponents': matchDateTimeComponents.index, + }, + ), + ); } @override @@ -973,16 +1004,13 @@ class MacOSFlutterLocalNotificationsPlugin String? payload, }) { validateId(id); - return _channel.invokeMethod( - 'show', - { - 'id': id, - 'title': title, - 'body': body, - 'payload': payload ?? '', - 'platformSpecifics': notificationDetails?.toMap(), - }, - ); + return _channel.invokeMethod('show', { + 'id': id, + 'title': title, + 'body': body, + 'payload': payload ?? '', + 'platformSpecifics': notificationDetails?.toMap(), + }); } @override @@ -1002,7 +1030,7 @@ class MacOSFlutterLocalNotificationsPlugin 'calledAt': clock.now().millisecondsSinceEpoch, 'repeatInterval': repeatInterval.index, 'platformSpecifics': notificationDetails?.toMap(), - 'payload': payload ?? '' + 'payload': payload ?? '', }); } @@ -1019,14 +1047,14 @@ class MacOSFlutterLocalNotificationsPlugin validateRepeatDurationInterval(repeatDurationInterval); await _channel .invokeMethod('periodicallyShowWithDuration', { - 'id': id, - 'title': title, - 'body': body, - 'calledAt': clock.now().millisecondsSinceEpoch, - 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, - 'platformSpecifics': notificationDetails?.toMap(), - 'payload': payload ?? '' - }); + 'id': id, + 'title': title, + 'body': body, + 'calledAt': clock.now().millisecondsSinceEpoch, + 'repeatIntervalMilliseconds': repeatDurationInterval.inMilliseconds, + 'platformSpecifics': notificationDetails?.toMap(), + 'payload': payload ?? '', + }); } Future _handleMethod(MethodCall call) async { @@ -1058,18 +1086,20 @@ class MacOSFlutterLocalNotificationsPlugin /// [arguments] map when the config is correct. void _evaluateBackgroundNotificationCallback( DidReceiveBackgroundNotificationResponseCallback? - didReceiveBackgroundNotificationResponseCallback, + didReceiveBackgroundNotificationResponseCallback, Map arguments, ) { if (didReceiveBackgroundNotificationResponseCallback != null) { final CallbackHandle? callback = PluginUtilities.getCallbackHandle( - didReceiveBackgroundNotificationResponseCallback); + didReceiveBackgroundNotificationResponseCallback, + ); assert(callback != null, ''' The backgroundHandler needs to be either a static function or a top level function to be accessible as a Flutter entry point.'''); - final CallbackHandle? dispatcher = - PluginUtilities.getCallbackHandle(callbackDispatcher); + final CallbackHandle? dispatcher = PluginUtilities.getCallbackHandle( + callbackDispatcher, + ); arguments['dispatcher_handle'] = dispatcher!.toRawHandle(); arguments['callback_handle'] = callback!.toRawHandle(); diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart b/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart index 3af775d16..b517b7a5c 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart @@ -46,7 +46,7 @@ enum AndroidNotificationStyle { messaging, /// The media style. - media + media, } /// Specifies the source for a sound used by Android notifications. @@ -65,7 +65,7 @@ enum AndroidNotificationChannelAction { /// Updates the details of an existing channel. Note that some details can /// not be changed once a channel has been created. - update + update, } /// The available foreground types for an Android service. @@ -136,7 +136,7 @@ enum AndroidServiceStartType { startNotSticky, /// Corresponds to [`Service.START_REDELIVER_INTENT`](https://developer.android.com/reference/android/app/Service#START_REDELIVER_INTENT). - startRedeliverIntent + startRedeliverIntent, } /// The available importance levels for Android notifications. @@ -205,7 +205,7 @@ enum GroupAlertBehavior { summary, /// The summary notification in a group should be silenced. - children + children, } /// Defines the notification visibility on the lockscreen. diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/message.dart b/flutter_local_notifications/lib/src/platform_specifics/android/message.dart index 4d42e2c49..92eefb17e 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/message.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/message.dart @@ -10,10 +10,10 @@ class Message { this.dataMimeType, this.dataUri, }) : assert( - (dataMimeType == null && dataUri == null) || - (dataMimeType != null && dataUri != null), - 'Must provide both dataMimeType and dataUri together or not at all.', - ); + (dataMimeType == null && dataUri == null) || + (dataMimeType != null && dataUri != null), + 'Must provide both dataMimeType and dataUri together or not at all.', + ); /// The message text final String text; diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/notification_channel_group.dart b/flutter_local_notifications/lib/src/platform_specifics/android/notification_channel_group.dart index 7a0559e71..9046e51ce 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/notification_channel_group.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/notification_channel_group.dart @@ -1,11 +1,7 @@ /// A group of related Android notification channels. class AndroidNotificationChannelGroup { /// Constructs an instance of [AndroidNotificationChannelGroup]. - const AndroidNotificationChannelGroup( - this.id, - this.name, { - this.description, - }); + const AndroidNotificationChannelGroup(this.id, this.name, {this.description}); /// The id of this group. final String id; diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/default_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/default_style_information.dart index e35b880b1..de08044d4 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/default_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/default_style_information.dart @@ -3,10 +3,7 @@ import 'style_information.dart'; /// The default Android notification style. class DefaultStyleInformation implements StyleInformation { /// Constructs an instance of [DefaultStyleInformation]. - const DefaultStyleInformation( - this.htmlFormatContent, - this.htmlFormatTitle, - ); + const DefaultStyleInformation(this.htmlFormatContent, this.htmlFormatTitle); /// Specifies if formatting should be applied to the content through HTML /// markup. diff --git a/flutter_local_notifications/lib/src/platform_specifics/darwin/interruption_level.dart b/flutter_local_notifications/lib/src/platform_specifics/darwin/interruption_level.dart index 00b1b0173..4a0eb0976 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/darwin/interruption_level.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/darwin/interruption_level.dart @@ -32,5 +32,5 @@ enum InterruptionLevel { /// https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/ /// /// Corresponds to [`UNNotificationInterruptionLevel.critical`](https://developer.apple.com/documentation/usernotifications/unnotificationinterruptionlevel/critical). - critical + critical, } diff --git a/flutter_local_notifications/lib/src/platform_specifics/darwin/mappers.dart b/flutter_local_notifications/lib/src/platform_specifics/darwin/mappers.dart index 687d9523d..f9e2b7a34 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/darwin/mappers.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/darwin/mappers.dart @@ -8,83 +8,83 @@ import 'notification_details.dart'; extension DarwinNotificationActionMapper on DarwinNotificationAction { Map toMap() => { - 'identifier': identifier, - 'title': title, - 'options': options - .map((e) => e.value) // ignore: always_specify_types - .toList(), - 'type': type.name, - if (buttonTitle != null) 'buttonTitle': buttonTitle!, - if (placeholder != null) 'placeholder': placeholder!, - }; + 'identifier': identifier, + 'title': title, + 'options': options + .map((e) => e.value) // ignore: always_specify_types + .toList(), + 'type': type.name, + if (buttonTitle != null) 'buttonTitle': buttonTitle!, + if (placeholder != null) 'placeholder': placeholder!, + }; } extension DarwinNotificationCategoryMapper on DarwinNotificationCategory { Map toMap() => { - 'identifier': identifier, - 'actions': actions - .map((e) => e.toMap()) // ignore: always_specify_types - .toList(), - 'options': options - .map((e) => e.value) // ignore: always_specify_types - .toList(), - }; + 'identifier': identifier, + 'actions': actions + .map((e) => e.toMap()) // ignore: always_specify_types + .toList(), + 'options': options + .map((e) => e.value) // ignore: always_specify_types + .toList(), + }; } extension DarwinInitializationSettingsMapper on DarwinInitializationSettings { Map toMap() => { - 'requestAlertPermission': requestAlertPermission, - 'requestSoundPermission': requestSoundPermission, - 'requestBadgePermission': requestBadgePermission, - 'requestProvisionalPermission': requestProvisionalPermission, - 'requestCriticalPermission': requestCriticalPermission, - 'requestProvidesAppNotificationSettings': - requestProvidesAppNotificationSettings, - 'defaultPresentAlert': defaultPresentAlert, - 'defaultPresentSound': defaultPresentSound, - 'defaultPresentBadge': defaultPresentBadge, - 'defaultPresentBanner': defaultPresentBanner, - 'defaultPresentList': defaultPresentList, - 'notificationCategories': notificationCategories - .map((e) => e.toMap()) // ignore: always_specify_types - .toList(), - }; + 'requestAlertPermission': requestAlertPermission, + 'requestSoundPermission': requestSoundPermission, + 'requestBadgePermission': requestBadgePermission, + 'requestProvisionalPermission': requestProvisionalPermission, + 'requestCriticalPermission': requestCriticalPermission, + 'requestProvidesAppNotificationSettings': + requestProvidesAppNotificationSettings, + 'defaultPresentAlert': defaultPresentAlert, + 'defaultPresentSound': defaultPresentSound, + 'defaultPresentBadge': defaultPresentBadge, + 'defaultPresentBanner': defaultPresentBanner, + 'defaultPresentList': defaultPresentList, + 'notificationCategories': notificationCategories + .map((e) => e.toMap()) // ignore: always_specify_types + .toList(), + }; } extension on DarwinNotificationAttachmentThumbnailClippingRect { Map toMap() => { - 'x': x, - 'y': y, - 'width': width, - 'height': height, - }; + 'x': x, + 'y': y, + 'width': width, + 'height': height, + }; } extension DarwinNotificationAttachmentMapper on DarwinNotificationAttachment { Map toMap() => { - 'identifier': identifier ?? '', - 'filePath': filePath, - 'hideThumbnail': hideThumbnail, - 'thumbnailClippingRect': thumbnailClippingRect?.toMap(), - }; + 'identifier': identifier ?? '', + 'filePath': filePath, + 'hideThumbnail': hideThumbnail, + 'thumbnailClippingRect': thumbnailClippingRect?.toMap(), + }; } extension DarwinNotificationDetailsMapper on DarwinNotificationDetails { Map toMap() => { - 'presentAlert': presentAlert, - 'presentSound': presentSound, - 'presentBadge': presentBadge, - 'presentBanner': presentBanner, - 'presentList': presentList, - 'subtitle': subtitle, - 'sound': sound, - 'badgeNumber': badgeNumber, - 'threadIdentifier': threadIdentifier, - 'interruptionLevel': interruptionLevel?.index, - 'attachments': attachments - ?.map((a) => a.toMap()) // ignore: always_specify_types - .toList(), - 'categoryIdentifier': categoryIdentifier, - 'criticalSoundVolume': criticalSoundVolume, - }; + 'presentAlert': presentAlert, + 'presentSound': presentSound, + 'presentBadge': presentBadge, + 'presentBanner': presentBanner, + 'presentList': presentList, + 'subtitle': subtitle, + 'sound': sound, + 'badgeNumber': badgeNumber, + 'threadIdentifier': threadIdentifier, + 'interruptionLevel': interruptionLevel?.index, + 'attachments': attachments + ?.map((a) => a.toMap()) // ignore: always_specify_types + .toList(), + 'categoryIdentifier': categoryIdentifier, + 'criticalSoundVolume': criticalSoundVolume, + }; } diff --git a/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_action.dart b/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_action.dart index fd19c8e01..2c432c9bc 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_action.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_action.dart @@ -25,13 +25,12 @@ class DarwinNotificationAction { String title, { Set options = const {}, - }) => - DarwinNotificationAction._( - _DarwinNotificationActionType.plain, - identifier, - title, - options: options, - ); + }) => DarwinNotificationAction._( + _DarwinNotificationActionType.plain, + identifier, + title, + options: options, + ); /// Creates a `UNTextInputNotificationAction` to collect user defined input. factory DarwinNotificationAction.text( @@ -41,15 +40,14 @@ class DarwinNotificationAction { String? placeholder, Set options = const {}, - }) => - DarwinNotificationAction._( - _DarwinNotificationActionType.text, - identifier, - title, - buttonTitle: buttonTitle, - placeholder: placeholder, - options: options, - ); + }) => DarwinNotificationAction._( + _DarwinNotificationActionType.text, + identifier, + title, + buttonTitle: buttonTitle, + placeholder: placeholder, + options: options, + ); const DarwinNotificationAction._( this.type, diff --git a/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_attachment.dart b/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_attachment.dart index ba7246ca6..e5f40f68d 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_attachment.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/darwin/notification_attachment.dart @@ -26,7 +26,7 @@ class DarwinNotificationAttachment { /// The clipping rectangle for the thumbnail image. final DarwinNotificationAttachmentThumbnailClippingRect? - thumbnailClippingRect; + thumbnailClippingRect; } /// Represents the clipping rectangle used for the thumbnail image. diff --git a/flutter_local_notifications/lib/src/typedefs.dart b/flutter_local_notifications/lib/src/typedefs.dart index 636c6fa3a..3ef4c5823 100644 --- a/flutter_local_notifications/lib/src/typedefs.dart +++ b/flutter_local_notifications/lib/src/typedefs.dart @@ -2,5 +2,5 @@ /// whilst the app is in the foreground. /// /// This property is only applicable to iOS versions older than 10. -typedef DidReceiveLocalNotificationCallback = void Function( - int id, String? title, String? body, String? payload); +typedef DidReceiveLocalNotificationCallback = + void Function(int id, String? title, String? body, String? payload); diff --git a/flutter_local_notifications/lib/src/tz_datetime_mapper.dart b/flutter_local_notifications/lib/src/tz_datetime_mapper.dart index 6e009819e..2c6d22d73 100644 --- a/flutter_local_notifications/lib/src/tz_datetime_mapper.dart +++ b/flutter_local_notifications/lib/src/tz_datetime_mapper.dart @@ -10,8 +10,9 @@ extension TZDateTimeMapper on TZDateTime { return '0$n'; } - final String offsetMinutesComponent = - twoDigits(timeZoneOffset.inMinutes.remainder(60)); + final String offsetMinutesComponent = twoDigits( + timeZoneOffset.inMinutes.remainder(60), + ); final int offsetHoursComponent = (timeZoneOffset.inMicroseconds ~/ Duration.microsecondsPerHour).abs(); final String iso8601OffsetComponent = diff --git a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart index f45e8f90e..bdd87d280 100644 --- a/flutter_local_notifications/test/android_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/android_flutter_local_notifications_test.dart @@ -19,8 +19,9 @@ void main() { late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; group('Android', () { - const MethodChannel channel = - MethodChannel('dexterous.com/flutter/local_notifications'); + const MethodChannel channel = MethodChannel( + 'dexterous.com/flutter/local_notifications', + ); final List log = []; setUp(() { @@ -28,18 +29,18 @@ void main() { flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, (MethodCall methodCall) async { - log.add(methodCall); - if (methodCall.method == 'initialize') { - return true; - } else if (methodCall.method == 'pendingNotificationRequests') { - return >[]; - } else if (methodCall.method == 'getActiveNotifications') { - return >[]; - } else if (methodCall.method == 'getNotificationAppLaunchDetails') { - return null; - } - return null; - }); + log.add(methodCall); + if (methodCall.method == 'initialize') { + return true; + } else if (methodCall.method == 'pendingNotificationRequests') { + return >[]; + } else if (methodCall.method == 'getActiveNotifications') { + return >[]; + } else if (methodCall.method == 'getNotificationAppLaunchDetails') { + return null; + } + return null; + }); }); tearDown(() { @@ -53,9 +54,10 @@ void main() { InitializationSettings(android: androidInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'defaultIcon': 'app_icon', - }) + isMethodCall( + 'initialize', + arguments: {'defaultIcon': 'app_icon'}, + ), ]); }); @@ -66,50 +68,58 @@ void main() { InitializationSettings(android: androidInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.show( - 1, 'notification title', 'notification body', null); + 1, + 'notification title', + 'notification body', + null, + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', 'payload': '', 'platformSpecifics': null, - })); + }, + ), + ); }); test('show with Android actions', () async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - actions: [ - AndroidNotificationAction( - 'action1', - 'Action 1', - titleColor: Color.fromARGB(255, 0, 127, 16), - contextual: true, - showsUserInterface: true, - allowGeneratedReplies: true, - cancelNotification: false, - semanticAction: SemanticAction.markAsRead, - invisible: true, - ), - AndroidNotificationAction( - 'action2', - 'Action 2', - titleColor: Color.fromARGB(255, 0, 127, 16), - inputs: [ - AndroidNotificationActionInput( - choices: ['choice1', 'choice2'], - label: 'Select something', - allowedMimeTypes: {'text/plain'}, + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + actions: [ + AndroidNotificationAction( + 'action1', + 'Action 1', + titleColor: Color.fromARGB(255, 0, 127, 16), + contextual: true, + showsUserInterface: true, + allowGeneratedReplies: true, + cancelNotification: false, + semanticAction: SemanticAction.markAsRead, + invisible: true, + ), + AndroidNotificationAction( + 'action2', + 'Action 2', + titleColor: Color.fromARGB(255, 0, 127, 16), + inputs: [ + AndroidNotificationActionInput( + choices: ['choice1', 'choice2'], + label: 'Select something', + allowedMimeTypes: {'text/plain'}, + ), + ], ), ], - ) - ], - ); + ); await flutterLocalNotificationsPlugin.show( 1, @@ -214,13 +224,13 @@ void main() { 'choices': ['choice1', 'choice2'], 'allowFreeFormInput': true, 'label': 'Select something', - 'allowedMimeType': ['text/plain'] - } + 'allowedMimeType': ['text/plain'], + }, ], 'cancelNotification': true, 'semanticAction': SemanticAction.none.value, 'invisible': false, - } + }, ], }, }, @@ -236,19 +246,22 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -311,269 +324,306 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); - test('show with default Android-specific details and additional flags', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', + test( + 'show with default Android-specific details and additional flags', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + final AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', channelDescription: 'channelDescription', - additionalFlags: Int32List.fromList([4, 32])); + additionalFlags: Int32List.fromList([4, 32]), + ); - await flutterLocalNotificationsPlugin.show( + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - NotificationDetails(android: androidNotificationDetails)); - expect( + NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'additionalFlags': [4, 32], - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'additionalFlags': [4, 32], + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); test( - 'show with default Android-specific details with a timestamp specified', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - final int timestamp = clock.now().millisecondsSinceEpoch; - - final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription', when: timestamp); - await flutterLocalNotificationsPlugin.show( + 'show with default Android-specific details with a timestamp specified', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + final int timestamp = clock.now().millisecondsSinceEpoch; + + final AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + when: timestamp, + ); + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - NotificationDetails(android: androidNotificationDetails)); - expect( + NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': timestamp, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, - }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': timestamp, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, + }, }, - })); - }); - - test('show with default Android-specific details with a chronometer', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - final int timestamp = clock.now().millisecondsSinceEpoch; + ), + ); + }, + ); - final AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', + test( + 'show with default Android-specific details with a chronometer', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + final int timestamp = clock.now().millisecondsSinceEpoch; + + final AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', channelDescription: 'channelDescription', when: timestamp, - usesChronometer: true); - await flutterLocalNotificationsPlugin.show( + usesChronometer: true, + ); + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - NotificationDetails(android: androidNotificationDetails)); - expect( + NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': timestamp, - 'usesChronometer': true, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': timestamp, + 'usesChronometer': true, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); - test( - 'show with default Android-specific details and custom sound from raw ' + test('show with default Android-specific details and custom sound from raw ' 'resource', () async { const AndroidInitializationSettings androidInitializationSettings = AndroidInitializationSettings('app_icon'); @@ -582,20 +632,23 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - sound: RawResourceAndroidNotificationSound('sound.mp3'), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + sound: RawResourceAndroidNotificationSound('sound.mp3'), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -660,485 +713,413 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); - test('show with default Android-specific details and custom sound from uri', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - sound: UriAndroidNotificationSound('uri'), - ); + test( + 'show with default Android-specific details and custom sound from uri', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + const AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + sound: UriAndroidNotificationSound('uri'), + ); - await flutterLocalNotificationsPlugin.show( + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - const NotificationDetails(android: androidNotificationDetails)); - expect( + const NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'sound': 'uri', - 'soundSource': AndroidNotificationSoundSource.uri.index, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'sound': 'uri', + 'soundSource': AndroidNotificationSoundSource.uri.index, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); - test('show with default Android-specific details and silent enabled', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - silent: true, - ); + test( + 'show with default Android-specific details and silent enabled', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + const AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + silent: true, + ); - await flutterLocalNotificationsPlugin.show( + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - const NotificationDetails(android: androidNotificationDetails)); - expect( + const NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': true, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': true, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); test( - 'show with default Android-specific details and html formatted title and content/body', - () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: DefaultStyleInformation(true, true), - ); - - await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); - expect( - log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': true, - 'htmlFormatTitle': true, - }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, - }, - })); - }); - - test( - 'show with default Android big picture style settings using a drawable ' - 'resource', () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: BigPictureStyleInformation( - DrawableResourceAndroidBitmap('bigPictureDrawable'), - ), - ); + 'show with default Android-specific details and html formatted title and content/body', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + const AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: DefaultStyleInformation(true, true), + ); - await flutterLocalNotificationsPlugin.show( + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - const NotificationDetails(android: androidNotificationDetails)); - expect( + const NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.bigPicture.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, - 'bigPicture': 'bigPictureDrawable', - 'bigPictureBitmapSource': AndroidBitmapSource.drawable.index, - 'contentTitle': null, - 'summaryText': null, - 'htmlFormatContentTitle': false, - 'htmlFormatSummaryText': false, - 'hideExpandedLargeIcon': false, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': true, + 'htmlFormatTitle': true, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); test( - 'show with non-default Android big picture style settings using a ' - 'drawable resource', () async { - const AndroidInitializationSettings androidInitializationSettings = - AndroidInitializationSettings('app_icon'); - const InitializationSettings initializationSettings = - InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin.initialize(initializationSettings); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: BigPictureStyleInformation( - DrawableResourceAndroidBitmap('bigPictureDrawable'), - contentTitle: 'contentTitle', - summaryText: 'summaryText', - htmlFormatContentTitle: true, - htmlFormatSummaryText: true, - largeIcon: DrawableResourceAndroidBitmap('largeDrawableIcon'), - htmlFormatContent: true, - htmlFormatTitle: true, - hideExpandedLargeIcon: true, - ), - ); + 'show with default Android big picture style settings using a drawable ' + 'resource', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + const AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: BigPictureStyleInformation( + DrawableResourceAndroidBitmap('bigPictureDrawable'), + ), + ); - await flutterLocalNotificationsPlugin.show( + await flutterLocalNotificationsPlugin.show( 1, 'notification title', 'notification body', - const NotificationDetails(android: androidNotificationDetails)); - expect( + const NotificationDetails(android: androidNotificationDetails), + ); + expect( log.last, - isMethodCall('show', arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.bigPicture.index, - 'styleInformation': { - 'htmlFormatContent': true, - 'htmlFormatTitle': true, - 'bigPicture': 'bigPictureDrawable', - 'bigPictureBitmapSource': AndroidBitmapSource.drawable.index, - 'largeIcon': 'largeDrawableIcon', - 'largeIconBitmapSource': AndroidBitmapSource.drawable.index, - 'contentTitle': 'contentTitle', - 'summaryText': 'summaryText', - 'htmlFormatContentTitle': true, - 'htmlFormatSummaryText': true, - 'hideExpandedLargeIcon': true, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.bigPicture.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + 'bigPicture': 'bigPictureDrawable', + 'bigPictureBitmapSource': AndroidBitmapSource.drawable.index, + 'contentTitle': null, + 'summaryText': null, + 'htmlFormatContentTitle': false, + 'htmlFormatSummaryText': false, + 'hideExpandedLargeIcon': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, }, - })); - }); + ), + ); + }, + ); - test( - 'show with default Android big picture style settings using a file ' - 'path', () async { + test('show with non-default Android big picture style settings using a ' + 'drawable resource', () async { const AndroidInitializationSettings androidInitializationSettings = AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = @@ -1146,22 +1127,33 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: BigPictureStyleInformation( - FilePathAndroidBitmap('bigPictureFilePath'), - ), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: BigPictureStyleInformation( + DrawableResourceAndroidBitmap('bigPictureDrawable'), + contentTitle: 'contentTitle', + summaryText: 'summaryText', + htmlFormatContentTitle: true, + htmlFormatSummaryText: true, + largeIcon: DrawableResourceAndroidBitmap('largeDrawableIcon'), + htmlFormatContent: true, + htmlFormatTitle: true, + hideExpandedLargeIcon: true, + ), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1215,27 +1207,30 @@ void main() { 'shortcutId': null, 'subText': null, 'style': AndroidNotificationStyle.bigPicture.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, - 'bigPicture': 'bigPictureFilePath', - 'bigPictureBitmapSource': AndroidBitmapSource.filePath.index, - 'contentTitle': null, - 'summaryText': null, - 'htmlFormatContentTitle': false, - 'htmlFormatSummaryText': false, - 'hideExpandedLargeIcon': false, + 'styleInformation': { + 'htmlFormatContent': true, + 'htmlFormatTitle': true, + 'bigPicture': 'bigPictureDrawable', + 'bigPictureBitmapSource': AndroidBitmapSource.drawable.index, + 'largeIcon': 'largeDrawableIcon', + 'largeIconBitmapSource': AndroidBitmapSource.drawable.index, + 'contentTitle': 'contentTitle', + 'summaryText': 'summaryText', + 'htmlFormatContentTitle': true, + 'htmlFormatSummaryText': true, + 'hideExpandedLargeIcon': true, }, 'tag': null, 'colorized': false, 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); - test( - 'show with non-default Android big picture style settings using a file ' + test('show with default Android big picture style settings using a file ' 'path', () async { const AndroidInitializationSettings androidInitializationSettings = AndroidInitializationSettings('app_icon'); @@ -1244,30 +1239,25 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: BigPictureStyleInformation( - FilePathAndroidBitmap('bigPictureFilePath'), - contentTitle: 'contentTitle', - summaryText: 'summaryText', - htmlFormatContentTitle: true, - htmlFormatSummaryText: true, - largeIcon: FilePathAndroidBitmap('largeFilePathIcon'), - htmlFormatContent: true, - htmlFormatTitle: true, - hideExpandedLargeIcon: true, - ), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: BigPictureStyleInformation( + FilePathAndroidBitmap('bigPictureFilePath'), + ), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1321,27 +1311,144 @@ void main() { 'shortcutId': null, 'subText': null, 'style': AndroidNotificationStyle.bigPicture.index, - 'styleInformation': { - 'htmlFormatContent': true, - 'htmlFormatTitle': true, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, 'bigPicture': 'bigPictureFilePath', 'bigPictureBitmapSource': AndroidBitmapSource.filePath.index, - 'largeIcon': 'largeFilePathIcon', - 'largeIconBitmapSource': AndroidBitmapSource.filePath.index, - 'contentTitle': 'contentTitle', - 'summaryText': 'summaryText', - 'htmlFormatContentTitle': true, - 'htmlFormatSummaryText': true, - 'hideExpandedLargeIcon': true, + 'contentTitle': null, + 'summaryText': null, + 'htmlFormatContentTitle': false, + 'htmlFormatSummaryText': false, + 'hideExpandedLargeIcon': false, }, 'tag': null, 'colorized': false, 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); + test( + 'show with non-default Android big picture style settings using a file ' + 'path', + () async { + const AndroidInitializationSettings androidInitializationSettings = + AndroidInitializationSettings('app_icon'); + const InitializationSettings initializationSettings = + InitializationSettings(android: androidInitializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); + const AndroidNotificationDetails androidNotificationDetails = + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: BigPictureStyleInformation( + FilePathAndroidBitmap('bigPictureFilePath'), + contentTitle: 'contentTitle', + summaryText: 'summaryText', + htmlFormatContentTitle: true, + htmlFormatSummaryText: true, + largeIcon: FilePathAndroidBitmap('largeFilePathIcon'), + htmlFormatContent: true, + htmlFormatTitle: true, + hideExpandedLargeIcon: true, + ), + ); + + await flutterLocalNotificationsPlugin.show( + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); + expect( + log.last, + isMethodCall( + 'show', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.bigPicture.index, + 'styleInformation': { + 'htmlFormatContent': true, + 'htmlFormatTitle': true, + 'bigPicture': 'bigPictureFilePath', + 'bigPictureBitmapSource': AndroidBitmapSource.filePath.index, + 'largeIcon': 'largeFilePathIcon', + 'largeIconBitmapSource': AndroidBitmapSource.filePath.index, + 'contentTitle': 'contentTitle', + 'summaryText': 'summaryText', + 'htmlFormatContentTitle': true, + 'htmlFormatSummaryText': true, + 'hideExpandedLargeIcon': true, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, + }, + }, + ), + ); + }, + ); + test('show with default Android inbox style settings', () async { const AndroidInitializationSettings androidInitializationSettings = AndroidInitializationSettings('app_icon'); @@ -1350,22 +1457,23 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: InboxStyleInformation( - ['line1'], - ), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: InboxStyleInformation(['line1']), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1434,7 +1542,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('show with non-default Android inbox style settings', () async { @@ -1445,29 +1555,32 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: InboxStyleInformation( - ['line1'], - htmlFormatLines: true, - htmlFormatContent: true, - htmlFormatContentTitle: true, - htmlFormatSummaryText: true, - htmlFormatTitle: true, - contentTitle: 'contentTitle', - summaryText: 'summaryText', - ), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: InboxStyleInformation( + ['line1'], + htmlFormatLines: true, + htmlFormatContent: true, + htmlFormatContentTitle: true, + htmlFormatSummaryText: true, + htmlFormatTitle: true, + contentTitle: 'contentTitle', + summaryText: 'summaryText', + ), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1536,7 +1649,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('show with default Android media style settings', () async { @@ -1547,20 +1662,23 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: MediaStyleInformation(), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: MediaStyleInformation(), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1623,7 +1741,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('show with non-default Android media style settings', () async { @@ -1634,23 +1754,26 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: MediaStyleInformation( - htmlFormatTitle: true, - htmlFormatContent: true, - ), - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: MediaStyleInformation( + htmlFormatTitle: true, + htmlFormatContent: true, + ), + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - const NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + const NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1713,7 +1836,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('show with default Android messaging style settings', () async { @@ -1725,29 +1850,26 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: MessagingStyleInformation( - const Person(name: 'name'), - messages: [ - Message( - 'message 1', - messageDateTime, - null, + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: MessagingStyleInformation( + const Person(name: 'name'), + messages: [Message('message 1', messageDateTime, null)], ), - ], - ), + ); + + await flutterLocalNotificationsPlugin.show( + 1, + 'notification title', + 'notification body', + NotificationDetails(android: androidNotificationDetails), ); - - await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - NotificationDetails(android: androidNotificationDetails)); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1820,7 +1942,7 @@ void main() { 'person': null, 'dataMimeType': null, 'dataUri': null, - } + }, ], }, 'tag': null, @@ -1828,7 +1950,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('show with non-default Android messaging style settings', () async { @@ -1840,40 +1964,43 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); final AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - styleInformation: MessagingStyleInformation( - const Person( - bot: true, - icon: DrawableResourceAndroidIcon('drawablePersonIcon'), - important: true, - key: 'key', - name: 'name', - uri: 'uri', - ), - conversationTitle: 'conversationTitle', - groupConversation: true, - messages: [ - Message( - 'message 1', - messageDateTime, - null, - dataMimeType: 'dataMimeType', - dataUri: 'dataUri', + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + styleInformation: MessagingStyleInformation( + const Person( + bot: true, + icon: DrawableResourceAndroidIcon('drawablePersonIcon'), + important: true, + key: 'key', + name: 'name', + uri: 'uri', + ), + conversationTitle: 'conversationTitle', + groupConversation: true, + messages: [ + Message( + 'message 1', + messageDateTime, + null, + dataMimeType: 'dataMimeType', + dataUri: 'dataUri', + ), + ], ), - ], - ), - ); + ); await flutterLocalNotificationsPlugin.show( - 1, - 'notification title', - 'notification body', - NotificationDetails(android: androidNotificationDetails)); + 1, + 'notification title', + 'notification body', + NotificationDetails(android: androidNotificationDetails), + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -1948,7 +2075,7 @@ void main() { 'person': null, 'dataMimeType': 'dataMimeType', 'dataUri': 'dataUri', - } + }, ], }, 'tag': null, @@ -1956,7 +2083,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); group('periodicallyShow', () { @@ -1968,12 +2097,16 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.periodicallyShow( 1, 'notification title', @@ -1984,8 +2117,10 @@ void main() { ); expect( - log.last, - isMethodCall('periodicallyShow', arguments: { + log.last, + isMethodCall( + 'periodicallyShow', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -2001,7 +2136,8 @@ void main() { 'channelShowBadge': true, 'channelBypassDnd': false, 'channelAction': AndroidNotificationChannelAction - .createIfNotExists.index, + .createIfNotExists + .index, 'importance': Importance.defaultImportance.value, 'priority': Priority.defaultPriority.value, 'playSound': true, @@ -2051,7 +2187,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); }); } @@ -2067,24 +2205,30 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); expect( - () async => await flutterLocalNotificationsPlugin - .periodicallyShowWithDuration( - 1, - 'notification title', - 'notification body', - thirtySeconds, - const NotificationDetails( - android: androidNotificationDetails), + () async => await flutterLocalNotificationsPlugin + .periodicallyShowWithDuration( + 1, + 'notification title', + 'notification body', + thirtySeconds, + const NotificationDetails( + android: androidNotificationDetails, ), - throwsA(isA())); + ), + throwsA(isA()), + ); }); }); @@ -2092,7 +2236,7 @@ void main() { const Duration(minutes: 1), const Duration(minutes: 15), const Duration(hours: 5), - const Duration(days: 30) + const Duration(days: 30), ]; for (final Duration repeatDurationInterval in repeatDurationIntervals) { @@ -2102,12 +2246,16 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.periodicallyShowWithDuration( 1, 'notification title', @@ -2117,76 +2265,80 @@ void main() { ); expect( - log.last, - isMethodCall('periodicallyShowWithDuration', - arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'calledAt': now.millisecondsSinceEpoch, - 'repeatIntervalMilliseconds': - repeatDurationInterval.inMilliseconds, - 'platformSpecifics': { - 'scheduleMode': 'exact', - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': AndroidNotificationChannelAction - .createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': null, - 'colorRed': null, - 'colorGreen': null, - 'colorBlue': null, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, - }, - 'tag': null, - 'colorized': false, - 'number': null, - 'audioAttributesUsage': 5, - }, - })); + log.last, + isMethodCall( + 'periodicallyShowWithDuration', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'calledAt': now.millisecondsSinceEpoch, + 'repeatIntervalMilliseconds': + repeatDurationInterval.inMilliseconds, + 'platformSpecifics': { + 'scheduleMode': 'exact', + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': AndroidNotificationChannelAction + .createIfNotExists + .index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': null, + 'colorRed': null, + 'colorGreen': null, + 'colorBlue': null, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, + }, + 'tag': null, + 'colorized': false, + 'number': null, + 'audioAttributesUsage': 5, + }, + }, + ), + ); }); }); } @@ -2198,25 +2350,33 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - const NotificationDetails(android: androidNotificationDetails), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); + 1, + 'notification title', + 'notification body', + scheduledDate, + const NotificationDetails(android: androidNotificationDetails), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -2283,7 +2443,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('match time components', () async { @@ -2291,27 +2453,35 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - const NotificationDetails(android: androidNotificationDetails), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.time); + 1, + 'notification title', + 'notification body', + scheduledDate, + const NotificationDetails(android: androidNotificationDetails), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.time, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -2379,7 +2549,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); test('match day of week and time components', () async { @@ -2387,27 +2559,35 @@ void main() { AndroidInitializationSettings('app_icon'); const InitializationSettings initializationSettings = InitializationSettings(android: androidInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('channelId', 'channelName', - channelDescription: 'channelDescription'); + AndroidNotificationDetails( + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - const NotificationDetails(android: androidNotificationDetails), - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime); + 1, + 'notification title', + 'notification body', + scheduledDate, + const NotificationDetails(android: androidNotificationDetails), + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -2476,7 +2656,9 @@ void main() { 'number': null, 'audioAttributesUsage': 5, }, - })); + }, + ), + ); }); }); @@ -2484,32 +2666,43 @@ void main() { test('without description', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .createNotificationChannelGroup( - const AndroidNotificationChannelGroup('groupId', 'groupName')); + const AndroidNotificationChannelGroup('groupId', 'groupName'), + ); expect(log, [ - isMethodCall('createNotificationChannelGroup', - arguments: { - 'id': 'groupId', - 'name': 'groupName', - 'description': null, - }) + isMethodCall( + 'createNotificationChannelGroup', + arguments: { + 'id': 'groupId', + 'name': 'groupName', + 'description': null, + }, + ), ]); }); test('with description', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .createNotificationChannelGroup( - const AndroidNotificationChannelGroup('groupId', 'groupName', - description: 'groupDescription')); + const AndroidNotificationChannelGroup( + 'groupId', + 'groupName', + description: 'groupDescription', + ), + ); expect(log, [ - isMethodCall('createNotificationChannelGroup', - arguments: { - 'id': 'groupId', - 'name': 'groupName', - 'description': 'groupDescription', - }) + isMethodCall( + 'createNotificationChannelGroup', + arguments: { + 'id': 'groupId', + 'name': 'groupName', + 'description': 'groupDescription', + }, + ), ]); }); }); @@ -2517,105 +2710,118 @@ void main() { test('createNotificationChannel with default settings', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! - .createNotificationChannel(const AndroidNotificationChannel( - 'channelId', - 'channelName', - description: 'channelDescription', - )); + AndroidFlutterLocalNotificationsPlugin + >()! + .createNotificationChannel( + const AndroidNotificationChannel( + 'channelId', + 'channelName', + description: 'channelDescription', + ), + ); expect(log, [ - isMethodCall('createNotificationChannel', arguments: { - 'id': 'channelId', - 'name': 'channelName', - 'description': 'channelDescription', - 'groupId': null, - 'showBadge': true, - 'importance': Importance.defaultImportance.value, - 'bypassDnd': false, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'audioAttributesUsage': AudioAttributesUsage.notification.value, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - }) + isMethodCall( + 'createNotificationChannel', + arguments: { + 'id': 'channelId', + 'name': 'channelName', + 'description': 'channelDescription', + 'groupId': null, + 'showBadge': true, + 'importance': Importance.defaultImportance.value, + 'bypassDnd': false, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'audioAttributesUsage': AudioAttributesUsage.notification.value, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + }, + ), ]); }); test('createNotificationChannel with non-default settings', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! - .createNotificationChannel(const AndroidNotificationChannel( - 'channelId', - 'channelName', - description: 'channelDescription', - groupId: 'channelGroupId', - showBadge: false, - bypassDnd: true, - importance: Importance.max, - playSound: false, - enableLights: true, - enableVibration: false, - ledColor: Color.fromARGB(255, 255, 0, 0), - audioAttributesUsage: AudioAttributesUsage.alarm, - )); + AndroidFlutterLocalNotificationsPlugin + >()! + .createNotificationChannel( + const AndroidNotificationChannel( + 'channelId', + 'channelName', + description: 'channelDescription', + groupId: 'channelGroupId', + showBadge: false, + bypassDnd: true, + importance: Importance.max, + playSound: false, + enableLights: true, + enableVibration: false, + ledColor: Color.fromARGB(255, 255, 0, 0), + audioAttributesUsage: AudioAttributesUsage.alarm, + ), + ); expect(log, [ - isMethodCall('createNotificationChannel', arguments: { - 'id': 'channelId', - 'name': 'channelName', - 'description': 'channelDescription', - 'groupId': 'channelGroupId', - 'showBadge': false, - 'importance': Importance.max.value, - 'bypassDnd': true, - 'playSound': false, - 'enableVibration': false, - 'vibrationPattern': null, - 'enableLights': true, - 'ledColorAlpha': 255, - 'ledColorRed': 255, - 'ledColorGreen': 0, - 'ledColorBlue': 0, - 'audioAttributesUsage': AudioAttributesUsage.alarm.value, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - }) + isMethodCall( + 'createNotificationChannel', + arguments: { + 'id': 'channelId', + 'name': 'channelName', + 'description': 'channelDescription', + 'groupId': 'channelGroupId', + 'showBadge': false, + 'importance': Importance.max.value, + 'bypassDnd': true, + 'playSound': false, + 'enableVibration': false, + 'vibrationPattern': null, + 'enableLights': true, + 'ledColorAlpha': 255, + 'ledColorRed': 255, + 'ledColorGreen': 0, + 'ledColorBlue': 0, + 'audioAttributesUsage': AudioAttributesUsage.alarm.value, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + }, + ), ]); }); test('deleteNotificationChannel', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .deleteNotificationChannel('channelId'); expect(log, [ - isMethodCall('deleteNotificationChannel', arguments: 'channelId') + isMethodCall('deleteNotificationChannel', arguments: 'channelId'), ]); }); test('cancel', () async { await flutterLocalNotificationsPlugin.cancel(1); expect(log, [ - isMethodCall('cancel', arguments: { - 'id': 1, - 'tag': null, - }) + isMethodCall( + 'cancel', + arguments: {'id': 1, 'tag': null}, + ), ]); }); test('cancel with tag', () async { await flutterLocalNotificationsPlugin.cancel(1, tag: 'tag'); expect(log, [ - isMethodCall('cancel', arguments: { - 'id': 1, - 'tag': 'tag', - }) + isMethodCall( + 'cancel', + arguments: {'id': 1, 'tag': 'tag'}, + ), ]); }); @@ -2627,27 +2833,28 @@ void main() { test('cancelAllPendingNotifications', () async { await flutterLocalNotificationsPlugin.cancelAllPendingNotifications(); expect(log, [ - isMethodCall('cancelAllPendingNotifications', arguments: null) + isMethodCall('cancelAllPendingNotifications', arguments: null), ]); }); test('pendingNotificationRequests', () async { await flutterLocalNotificationsPlugin.pendingNotificationRequests(); expect(log, [ - isMethodCall('pendingNotificationRequests', arguments: null) + isMethodCall('pendingNotificationRequests', arguments: null), ]); }); test('getActiveNotifications', () async { await flutterLocalNotificationsPlugin.getActiveNotifications(); - expect(log, - [isMethodCall('getActiveNotifications', arguments: null)]); + expect(log, [ + isMethodCall('getActiveNotifications', arguments: null), + ]); }); test('getNotificationAppLaunchDetails', () async { await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); expect(log, [ - isMethodCall('getNotificationAppLaunchDetails', arguments: null) + isMethodCall('getNotificationAppLaunchDetails', arguments: null), ]); }); @@ -2659,11 +2866,14 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .startForegroundService(1, 'notification title', 'notification body'); expect( - log.last, - isMethodCall('startForegroundService', arguments: { + log.last, + isMethodCall( + 'startForegroundService', + arguments: { 'notificationData': { 'id': 1, 'title': 'notification title', @@ -2672,30 +2882,31 @@ void main() { 'platformSpecifics': null, }, 'startType': AndroidServiceStartType.startSticky.index, - 'foregroundServiceTypes': null - })); + 'foregroundServiceTypes': null, + }, + ), + ); }); test('stopForegroundService', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .stopForegroundService(); - expect( - log.last, - isMethodCall( - 'stopForegroundService', - arguments: null, - )); + expect(log.last, isMethodCall('stopForegroundService', arguments: null)); }); test('areNotificationsEnabled', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .areNotificationsEnabled(); expect( - log.last, isMethodCall('areNotificationsEnabled', arguments: null)); + log.last, + isMethodCall('areNotificationsEnabled', arguments: null), + ); }); test('startForegroundServiceWithBlueBackgroundNotification', () async { @@ -2706,110 +2917,121 @@ void main() { await flutterLocalNotificationsPlugin.initialize(initializationSettings); const AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails( - 'channelId', - 'channelName', - channelDescription: 'channelDescription', - color: Colors.blue, - colorized: true, - ); + 'channelId', + 'channelName', + channelDescription: 'channelDescription', + color: Colors.blue, + colorized: true, + ); await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! - .startForegroundService(1, 'colored background notification title', - 'colored background notification body', - notificationDetails: androidPlatformChannelSpecifics); + AndroidFlutterLocalNotificationsPlugin + >()! + .startForegroundService( + 1, + 'colored background notification title', + 'colored background notification body', + notificationDetails: androidPlatformChannelSpecifics, + ); expect( - log.last, - isMethodCall( - 'startForegroundService', - arguments: { - 'notificationData': { - 'id': 1, - 'title': 'colored background notification title', - 'body': 'colored background notification body', - 'payload': '', - 'platformSpecifics': { - 'icon': null, - 'channelId': 'channelId', - 'channelName': 'channelName', - 'channelDescription': 'channelDescription', - 'channelShowBadge': true, - 'channelBypassDnd': false, - 'channelAction': - AndroidNotificationChannelAction.createIfNotExists.index, - 'importance': Importance.defaultImportance.value, - 'priority': Priority.defaultPriority.value, - 'playSound': true, - 'enableVibration': true, - 'vibrationPattern': null, - 'groupKey': null, - 'setAsGroupSummary': false, - 'groupAlertBehavior': GroupAlertBehavior.all.index, - 'autoCancel': true, - 'ongoing': false, - 'silent': false, - 'colorAlpha': 255, - 'colorRed': 33, - 'colorGreen': 150, - 'colorBlue': 243, - 'onlyAlertOnce': false, - 'showWhen': true, - 'when': null, - 'usesChronometer': false, - 'chronometerCountDown': false, - 'showProgress': false, - 'maxProgress': 0, - 'progress': 0, - 'indeterminate': false, - 'enableLights': false, - 'ledColorAlpha': null, - 'ledColorRed': null, - 'ledColorGreen': null, - 'ledColorBlue': null, - 'ledOnMs': null, - 'ledOffMs': null, - 'ticker': null, - 'visibility': null, - 'timeoutAfter': null, - 'category': null, - 'additionalFlags': null, - 'fullScreenIntent': false, - 'shortcutId': null, - 'subText': null, - 'style': AndroidNotificationStyle.defaultStyle.index, - 'styleInformation': { - 'htmlFormatContent': false, - 'htmlFormatTitle': false, - }, - 'tag': null, - 'colorized': true, - 'number': null, - 'audioAttributesUsage': 5, + log.last, + isMethodCall( + 'startForegroundService', + arguments: { + 'notificationData': { + 'id': 1, + 'title': 'colored background notification title', + 'body': 'colored background notification body', + 'payload': '', + 'platformSpecifics': { + 'icon': null, + 'channelId': 'channelId', + 'channelName': 'channelName', + 'channelDescription': 'channelDescription', + 'channelShowBadge': true, + 'channelBypassDnd': false, + 'channelAction': + AndroidNotificationChannelAction.createIfNotExists.index, + 'importance': Importance.defaultImportance.value, + 'priority': Priority.defaultPriority.value, + 'playSound': true, + 'enableVibration': true, + 'vibrationPattern': null, + 'groupKey': null, + 'setAsGroupSummary': false, + 'groupAlertBehavior': GroupAlertBehavior.all.index, + 'autoCancel': true, + 'ongoing': false, + 'silent': false, + 'colorAlpha': 255, + 'colorRed': 33, + 'colorGreen': 150, + 'colorBlue': 243, + 'onlyAlertOnce': false, + 'showWhen': true, + 'when': null, + 'usesChronometer': false, + 'chronometerCountDown': false, + 'showProgress': false, + 'maxProgress': 0, + 'progress': 0, + 'indeterminate': false, + 'enableLights': false, + 'ledColorAlpha': null, + 'ledColorRed': null, + 'ledColorGreen': null, + 'ledColorBlue': null, + 'ledOnMs': null, + 'ledOffMs': null, + 'ticker': null, + 'visibility': null, + 'timeoutAfter': null, + 'category': null, + 'additionalFlags': null, + 'fullScreenIntent': false, + 'shortcutId': null, + 'subText': null, + 'style': AndroidNotificationStyle.defaultStyle.index, + 'styleInformation': { + 'htmlFormatContent': false, + 'htmlFormatTitle': false, }, + 'tag': null, + 'colorized': true, + 'number': null, + 'audioAttributesUsage': 5, }, - 'startType': AndroidServiceStartType.startSticky.index, - 'foregroundServiceTypes': null }, - )); + 'startType': AndroidServiceStartType.startSticky.index, + 'foregroundServiceTypes': null, + }, + ), + ); }); test('requestNotificationsPermission', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .requestNotificationsPermission(); - expect(log.last, - isMethodCall('requestNotificationsPermission', arguments: null)); + expect( + log.last, + isMethodCall('requestNotificationsPermission', arguments: null), + ); }); test('requestExactAlarmsPermission', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>()! + AndroidFlutterLocalNotificationsPlugin + >()! .requestExactAlarmsPermission(); - expect(log.last, - isMethodCall('requestExactAlarmsPermission', arguments: null)); + expect( + log.last, + isMethodCall('requestExactAlarmsPermission', arguments: null), + ); }); }); } diff --git a/flutter_local_notifications/test/flutter_local_notifications_test.dart b/flutter_local_notifications/test/flutter_local_notifications_test.dart index 5d406805f..b8693cc3f 100644 --- a/flutter_local_notifications/test/flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/flutter_local_notifications_test.dart @@ -12,8 +12,10 @@ void main() { FlutterLocalNotificationsPlatform.instance = mock; test('Creates DarwinNotificationAttachment when file path is specified', () { - expect(const DarwinNotificationAttachment(''), - isA()); + expect( + const DarwinNotificationAttachment(''), + isA(), + ); }); group('providesAppNotificationSettings tests', () { @@ -26,22 +28,21 @@ void main() { test('initialization can be set to true', () { const DarwinInitializationSettings settings = DarwinInitializationSettings( - requestProvidesAppNotificationSettings: true, - ); + requestProvidesAppNotificationSettings: true, + ); expect(settings.requestProvidesAppNotificationSettings, true); }); test('maps correctly to platform specific map', () { const DarwinInitializationSettings settings = DarwinInitializationSettings( - requestProvidesAppNotificationSettings: true, - ); + requestProvidesAppNotificationSettings: true, + ); final Map map = settings.toMap(); expect(map['requestProvidesAppNotificationSettings'], true); }); - test( - 'NotificationsEnabledOptions stores ' + test('NotificationsEnabledOptions stores ' 'providesAppNotificationSettings value', () async { const NotificationsEnabledOptions options = NotificationsEnabledOptions( isEnabled: true, @@ -62,5 +63,4 @@ class MockMethodChannel extends Mock implements MethodChannel {} class MockFlutterLocalNotificationsPlugin extends Mock with MockPlatformInterfaceMixin // ignore: prefer_mixin - implements - FlutterLocalNotificationsPlatform {} + implements FlutterLocalNotificationsPlatform {} diff --git a/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart b/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart index f6e66db05..8036bed35 100644 --- a/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/ios_flutter_local_notifications_test.dart @@ -14,8 +14,9 @@ void main() { late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; group('iOS', () { - const MethodChannel channel = - MethodChannel('dexterous.com/flutter/local_notifications'); + const MethodChannel channel = MethodChannel( + 'dexterous.com/flutter/local_notifications', + ); final List log = []; setUp(() { @@ -23,16 +24,16 @@ void main() { flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, (MethodCall methodCall) async { - log.add(methodCall); - if (methodCall.method == 'pendingNotificationRequests') { - return ?>[]; - } else if (methodCall.method == 'getActiveNotifications') { - return ?>[]; - } else if (methodCall.method == 'getNotificationAppLaunchDetails') { - return null; - } - return null; - }); + log.add(methodCall); + if (methodCall.method == 'pendingNotificationRequests') { + return ?>[]; + } else if (methodCall.method == 'getActiveNotifications') { + return ?>[]; + } else if (methodCall.method == 'getNotificationAppLaunchDetails') { + return null; + } + return null; + }); }); tearDown(() { @@ -46,157 +47,166 @@ void main() { InitializationSettings(iOS: iosInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'requestAlertPermission': true, - 'requestSoundPermission': true, - 'requestBadgePermission': true, - 'requestProvisionalPermission': false, - 'requestCriticalPermission': false, - 'requestProvidesAppNotificationSettings': false, - 'defaultPresentAlert': true, - 'defaultPresentSound': true, - 'defaultPresentBadge': true, - 'defaultPresentBanner': true, - 'defaultPresentList': true, - 'notificationCategories': [], - }) + isMethodCall( + 'initialize', + arguments: { + 'requestAlertPermission': true, + 'requestSoundPermission': true, + 'requestBadgePermission': true, + 'requestProvisionalPermission': false, + 'requestCriticalPermission': false, + 'requestProvidesAppNotificationSettings': false, + 'defaultPresentAlert': true, + 'defaultPresentSound': true, + 'defaultPresentBadge': true, + 'defaultPresentBanner': true, + 'defaultPresentList': true, + 'notificationCategories': [], + }, + ), ]); }); test('initialize with notification categories', () async { final DarwinInitializationSettings iosInitializationSettings = DarwinInitializationSettings( - notificationCategories: [ - DarwinNotificationCategory( - 'category1', - actions: [ - DarwinNotificationAction.plain( - 'action1', - 'Action 1', - options: { - DarwinNotificationActionOption.destructive, + notificationCategories: [ + DarwinNotificationCategory( + 'category1', + actions: [ + DarwinNotificationAction.plain( + 'action1', + 'Action 1', + options: { + DarwinNotificationActionOption.destructive, + }, + ), + ], + options: { + DarwinNotificationCategoryOption.allowAnnouncement, }, ), - ], - options: { - DarwinNotificationCategoryOption.allowAnnouncement, - }, - ), - DarwinNotificationCategory( - 'category2', - actions: [ - DarwinNotificationAction.plain('action2', 'Action 2'), - DarwinNotificationAction.plain('action3', 'Action 3'), - ], - ), - DarwinNotificationCategory( - 'category3', - actions: [ - DarwinNotificationAction.text( - 'action4', - 'Action 4', - buttonTitle: 'Send', - placeholder: 'Placeholder', + DarwinNotificationCategory( + 'category2', + actions: [ + DarwinNotificationAction.plain('action2', 'Action 2'), + DarwinNotificationAction.plain('action3', 'Action 3'), + ], + ), + DarwinNotificationCategory( + 'category3', + actions: [ + DarwinNotificationAction.text( + 'action4', + 'Action 4', + buttonTitle: 'Send', + placeholder: 'Placeholder', + ), + ], ), ], - ) - ], - ); + ); final InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'requestAlertPermission': true, - 'requestSoundPermission': true, - 'requestBadgePermission': true, - 'requestProvisionalPermission': false, - 'requestCriticalPermission': false, - 'requestProvidesAppNotificationSettings': false, - 'defaultPresentAlert': true, - 'defaultPresentSound': true, - 'defaultPresentBadge': true, - 'defaultPresentBanner': true, - 'defaultPresentList': true, - 'notificationCategories': >[ - { - 'identifier': 'category1', - 'actions': >[ - { - 'type': 'plain', - 'identifier': 'action1', - 'title': 'Action 1', - 'options': [2], - } - ], - 'options': [16], - }, - { - 'identifier': 'category2', - 'actions': >[ - { - 'type': 'plain', - 'identifier': 'action2', - 'title': 'Action 2', - 'options': [], - }, - { - 'type': 'plain', - 'identifier': 'action3', - 'title': 'Action 3', - 'options': [], - }, - ], - 'options': [], - }, - { - 'identifier': 'category3', - 'actions': >[ - { - 'type': 'text', - 'identifier': 'action4', - 'title': 'Action 4', - 'options': [], - 'buttonTitle': 'Send', - 'placeholder': 'Placeholder', - }, - ], - 'options': [], - } - ], - }) + isMethodCall( + 'initialize', + arguments: { + 'requestAlertPermission': true, + 'requestSoundPermission': true, + 'requestBadgePermission': true, + 'requestProvisionalPermission': false, + 'requestCriticalPermission': false, + 'requestProvidesAppNotificationSettings': false, + 'defaultPresentAlert': true, + 'defaultPresentSound': true, + 'defaultPresentBadge': true, + 'defaultPresentBanner': true, + 'defaultPresentList': true, + 'notificationCategories': >[ + { + 'identifier': 'category1', + 'actions': >[ + { + 'type': 'plain', + 'identifier': 'action1', + 'title': 'Action 1', + 'options': [2], + }, + ], + 'options': [16], + }, + { + 'identifier': 'category2', + 'actions': >[ + { + 'type': 'plain', + 'identifier': 'action2', + 'title': 'Action 2', + 'options': [], + }, + { + 'type': 'plain', + 'identifier': 'action3', + 'title': 'Action 3', + 'options': [], + }, + ], + 'options': [], + }, + { + 'identifier': 'category3', + 'actions': >[ + { + 'type': 'text', + 'identifier': 'action4', + 'title': 'Action 4', + 'options': [], + 'buttonTitle': 'Send', + 'placeholder': 'Placeholder', + }, + ], + 'options': [], + }, + ], + }, + ), ]); }); test('initialize with all settings off', () async { const DarwinInitializationSettings iosInitializationSettings = DarwinInitializationSettings( - requestAlertPermission: false, - requestBadgePermission: false, - requestSoundPermission: false, - defaultPresentAlert: false, - defaultPresentBadge: false, - defaultPresentSound: false, - defaultPresentBanner: false, - defaultPresentList: false, - ); + requestAlertPermission: false, + requestBadgePermission: false, + requestSoundPermission: false, + defaultPresentAlert: false, + defaultPresentBadge: false, + defaultPresentSound: false, + defaultPresentBanner: false, + defaultPresentList: false, + ); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'requestAlertPermission': false, - 'requestSoundPermission': false, - 'requestBadgePermission': false, - 'requestProvisionalPermission': false, - 'requestCriticalPermission': false, - 'requestProvidesAppNotificationSettings': false, - 'defaultPresentAlert': false, - 'defaultPresentSound': false, - 'defaultPresentBadge': false, - 'defaultPresentBanner': false, - 'defaultPresentList': false, - 'notificationCategories': [], - }) + isMethodCall( + 'initialize', + arguments: { + 'requestAlertPermission': false, + 'requestSoundPermission': false, + 'requestBadgePermission': false, + 'requestProvisionalPermission': false, + 'requestCriticalPermission': false, + 'requestProvidesAppNotificationSettings': false, + 'defaultPresentAlert': false, + 'defaultPresentSound': false, + 'defaultPresentBadge': false, + 'defaultPresentBanner': false, + 'defaultPresentList': false, + 'notificationCategories': [], + }, + ), ]); }); @@ -207,16 +217,24 @@ void main() { InitializationSettings(iOS: iosInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.show( - 1, 'notification title', 'notification body', null); + 1, + 'notification title', + 'notification body', + null, + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', 'payload': '', 'platformSpecifics': null, - })); + }, + ), + ); }); test('show with iOS-specific details', () async { @@ -236,8 +254,10 @@ void main() { sound: 'sound.mp3', badgeNumber: 1, attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373'), + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), ], categoryIdentifier: 'category1', criticalSoundVolume: 0.5, @@ -245,11 +265,17 @@ void main() { ); await flutterLocalNotificationsPlugin.show( - 1, 'notification title', 'notification body', notificationDetails); + 1, + 'notification title', + 'notification body', + notificationDetails, + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -270,13 +296,15 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': 'category1', 'interruptionLevel': null, 'criticalSoundVolume': 0.5, }, - })); + }, + ), + ); }); group('periodicallyShow', () { @@ -288,8 +316,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( iOS: DarwinNotificationDetails( @@ -304,18 +333,19 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); await flutterLocalNotificationsPlugin.periodicallyShow( - 1, - 'notification title', - 'notification body', - repeatInterval, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exact); + 1, + 'notification title', + 'notification body', + repeatInterval, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exact, + ); expect( log.last, @@ -344,7 +374,7 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, @@ -368,8 +398,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( iOS: DarwinNotificationDetails( @@ -384,21 +415,22 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); expect( - () async => await flutterLocalNotificationsPlugin - .periodicallyShowWithDuration( - 1, - 'notification title', - 'notification body', - thirtySeconds, - notificationDetails, - ), - throwsA(isA())); + () async => await flutterLocalNotificationsPlugin + .periodicallyShowWithDuration( + 1, + 'notification title', + 'notification body', + thirtySeconds, + notificationDetails, + ), + throwsA(isA()), + ); }); }); @@ -406,7 +438,7 @@ void main() { const Duration(minutes: 1), const Duration(minutes: 15), const Duration(hours: 5), - const Duration(days: 30) + const Duration(days: 30), ]; for (final Duration repeatDurationInterval in repeatDurationIntervals) { test('$repeatDurationInterval', () async { @@ -415,8 +447,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( iOS: DarwinNotificationDetails( @@ -431,7 +464,7 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); @@ -472,7 +505,7 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, @@ -492,37 +525,46 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( - iOS: DarwinNotificationDetails( - presentAlert: true, - presentBadge: true, - presentSound: true, - presentBanner: true, - presentList: true, - sound: 'sound.mp3', - badgeNumber: 1, - attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') - ])); + iOS: DarwinNotificationDetails( + presentAlert: true, + presentBadge: true, + presentSound: true, + presentBanner: true, + presentList: true, + sound: 'sound.mp3', + badgeNumber: 1, + attachments: [ + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), + ], + ), + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); + 1, + 'notification title', + 'notification body', + scheduledDate, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -546,13 +588,15 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, 'criticalSoundVolume': null, }, - })); + }, + ), + ); }); test('match time components', () async { @@ -560,38 +604,47 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( - iOS: DarwinNotificationDetails( - presentAlert: true, - presentBadge: true, - presentSound: true, - presentBanner: true, - presentList: true, - sound: 'sound.mp3', - badgeNumber: 1, - attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') - ])); + iOS: DarwinNotificationDetails( + presentAlert: true, + presentBadge: true, + presentSound: true, + presentBanner: true, + presentList: true, + sound: 'sound.mp3', + badgeNumber: 1, + attachments: [ + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), + ], + ), + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.time); + 1, + 'notification title', + 'notification body', + scheduledDate, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.time, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -616,13 +669,15 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, 'criticalSoundVolume': null, }, - })); + }, + ), + ); }); test('match day of week and time components', () async { @@ -630,38 +685,47 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( - iOS: DarwinNotificationDetails( - presentAlert: true, - presentBadge: true, - presentSound: true, - presentBanner: true, - presentList: true, - sound: 'sound.mp3', - badgeNumber: 1, - attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') - ])); + iOS: DarwinNotificationDetails( + presentAlert: true, + presentBadge: true, + presentSound: true, + presentBanner: true, + presentList: true, + sound: 'sound.mp3', + badgeNumber: 1, + attachments: [ + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), + ], + ), + ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime); + 1, + 'notification title', + 'notification body', + scheduledDate, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -687,58 +751,70 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, 'criticalSoundVolume': null, }, - })); + }, + ), + ); }); }); test('requestPermissions with default settings', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>()! + IOSFlutterLocalNotificationsPlugin + >()! .requestPermissions(); expect(log, [ - isMethodCall('requestPermissions', arguments: { - 'sound': false, - 'badge': false, - 'alert': false, - 'provisional': false, - 'critical': false, - 'providesAppNotificationSettings': false - }) + isMethodCall( + 'requestPermissions', + arguments: { + 'sound': false, + 'badge': false, + 'alert': false, + 'provisional': false, + 'critical': false, + 'providesAppNotificationSettings': false, + }, + ), ]); }); test('iOS requestPermissions with all settings requested', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>()! + IOSFlutterLocalNotificationsPlugin + >()! .requestPermissions( - sound: true, - badge: true, - alert: true, - provisional: true, - critical: true, - providesAppNotificationSettings: true); + sound: true, + badge: true, + alert: true, + provisional: true, + critical: true, + providesAppNotificationSettings: true, + ); expect(log, [ - isMethodCall('requestPermissions', arguments: { - 'sound': true, - 'badge': true, - 'alert': true, - 'provisional': true, - 'critical': true, - 'providesAppNotificationSettings': true, - }) + isMethodCall( + 'requestPermissions', + arguments: { + 'sound': true, + 'badge': true, + 'alert': true, + 'provisional': true, + 'critical': true, + 'providesAppNotificationSettings': true, + }, + ), ]); }); test('checkPermissions', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>()! + IOSFlutterLocalNotificationsPlugin + >()! .checkPermissions(); expect(log, [isMethodCall('checkPermissions', arguments: null)]); }); @@ -756,35 +832,36 @@ void main() { test('cancelAllPendingNotifications', () async { await flutterLocalNotificationsPlugin.cancelAllPendingNotifications(); expect(log, [ - isMethodCall('cancelAllPendingNotifications', arguments: null) + isMethodCall('cancelAllPendingNotifications', arguments: null), ]); }); test('pendingNotificationRequests', () async { await flutterLocalNotificationsPlugin.pendingNotificationRequests(); expect(log, [ - isMethodCall('pendingNotificationRequests', arguments: null) + isMethodCall('pendingNotificationRequests', arguments: null), ]); }); test('getActiveNotifications', () async { await flutterLocalNotificationsPlugin.getActiveNotifications(); - expect(log, - [isMethodCall('getActiveNotifications', arguments: null)]); + expect(log, [ + isMethodCall('getActiveNotifications', arguments: null), + ]); }); test('getNotificationAppLaunchDetails', () async { await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); expect(log, [ - isMethodCall('getNotificationAppLaunchDetails', arguments: null) + isMethodCall('getNotificationAppLaunchDetails', arguments: null), ]); }); test('initialize with providesAppNotificationSettings', () async { const DarwinInitializationSettings iosInitializationSettings = DarwinInitializationSettings( - requestProvidesAppNotificationSettings: true, - ); + requestProvidesAppNotificationSettings: true, + ); const InitializationSettings initializationSettings = InitializationSettings(iOS: iosInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); @@ -809,26 +886,33 @@ void main() { ]); }); - test('iOS requestPermissions with providesAppNotificationSettings', - () async { - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - IOSFlutterLocalNotificationsPlugin>()! - .requestPermissions( + test( + 'iOS requestPermissions with providesAppNotificationSettings', + () async { + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin + >()! + .requestPermissions( sound: true, alert: true, badge: true, - providesAppNotificationSettings: true); - expect(log, [ - isMethodCall('requestPermissions', arguments: { - 'sound': true, - 'alert': true, - 'badge': true, - 'provisional': false, - 'critical': false, - 'providesAppNotificationSettings': true - }) - ]); - }); + providesAppNotificationSettings: true, + ); + expect(log, [ + isMethodCall( + 'requestPermissions', + arguments: { + 'sound': true, + 'alert': true, + 'badge': true, + 'provisional': false, + 'critical': false, + 'providesAppNotificationSettings': true, + }, + ), + ]); + }, + ); }); } diff --git a/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart b/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart index 44359dc66..abb518dde 100644 --- a/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart +++ b/flutter_local_notifications/test/macos_flutter_local_notifications_test.dart @@ -13,8 +13,9 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; group('macOS', () { - const MethodChannel channel = - MethodChannel('dexterous.com/flutter/local_notifications'); + const MethodChannel channel = MethodChannel( + 'dexterous.com/flutter/local_notifications', + ); final List log = []; setUp(() { @@ -22,16 +23,16 @@ void main() { flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler(channel, (MethodCall methodCall) async { - log.add(methodCall); - if (methodCall.method == 'pendingNotificationRequests') { - return ?>[]; - } else if (methodCall.method == 'getActiveNotifications') { - return ?>[]; - } else if (methodCall.method == 'getNotificationAppLaunchDetails') { - return null; - } - return null; - }); + log.add(methodCall); + if (methodCall.method == 'pendingNotificationRequests') { + return ?>[]; + } else if (methodCall.method == 'getActiveNotifications') { + return ?>[]; + } else if (methodCall.method == 'getNotificationAppLaunchDetails') { + return null; + } + return null; + }); }); tearDown(() { @@ -45,53 +46,59 @@ void main() { InitializationSettings(macOS: macOSInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'requestAlertPermission': true, - 'requestSoundPermission': true, - 'requestBadgePermission': true, - 'requestProvisionalPermission': false, - 'requestCriticalPermission': false, - 'requestProvidesAppNotificationSettings': false, - 'defaultPresentAlert': true, - 'defaultPresentSound': true, - 'defaultPresentBadge': true, - 'defaultPresentBanner': true, - 'defaultPresentList': true, - 'notificationCategories': >[], - }) + isMethodCall( + 'initialize', + arguments: { + 'requestAlertPermission': true, + 'requestSoundPermission': true, + 'requestBadgePermission': true, + 'requestProvisionalPermission': false, + 'requestCriticalPermission': false, + 'requestProvidesAppNotificationSettings': false, + 'defaultPresentAlert': true, + 'defaultPresentSound': true, + 'defaultPresentBadge': true, + 'defaultPresentBanner': true, + 'defaultPresentList': true, + 'notificationCategories': >[], + }, + ), ]); }); test('initialize with all settings off', () async { const DarwinInitializationSettings macOSInitializationSettings = DarwinInitializationSettings( - requestAlertPermission: false, - requestBadgePermission: false, - requestSoundPermission: false, - defaultPresentAlert: false, - defaultPresentBadge: false, - defaultPresentSound: false, - defaultPresentBanner: false, - defaultPresentList: false, - ); + requestAlertPermission: false, + requestBadgePermission: false, + requestSoundPermission: false, + defaultPresentAlert: false, + defaultPresentBadge: false, + defaultPresentSound: false, + defaultPresentBanner: false, + defaultPresentList: false, + ); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); expect(log, [ - isMethodCall('initialize', arguments: { - 'requestAlertPermission': false, - 'requestSoundPermission': false, - 'requestBadgePermission': false, - 'requestProvisionalPermission': false, - 'requestCriticalPermission': false, - 'requestProvidesAppNotificationSettings': false, - 'defaultPresentAlert': false, - 'defaultPresentSound': false, - 'defaultPresentBadge': false, - 'defaultPresentBanner': false, - 'defaultPresentList': false, - 'notificationCategories': >[], - }) + isMethodCall( + 'initialize', + arguments: { + 'requestAlertPermission': false, + 'requestSoundPermission': false, + 'requestBadgePermission': false, + 'requestProvisionalPermission': false, + 'requestCriticalPermission': false, + 'requestProvidesAppNotificationSettings': false, + 'defaultPresentAlert': false, + 'defaultPresentSound': false, + 'defaultPresentBadge': false, + 'defaultPresentBanner': false, + 'defaultPresentList': false, + 'notificationCategories': >[], + }, + ), ]); }); @@ -102,16 +109,24 @@ void main() { InitializationSettings(macOS: macOSInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.show( - 1, 'notification title', 'notification body', null); + 1, + 'notification title', + 'notification body', + null, + ); expect( - log.last, - isMethodCall('show', arguments: { + log.last, + isMethodCall( + 'show', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', 'payload': '', 'platformSpecifics': null, - })); + }, + ), + ); }); test('show with macOS-specific details', () async { @@ -175,7 +190,7 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': 'category1', 'interruptionLevel': 2, @@ -195,8 +210,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( @@ -211,7 +227,7 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); @@ -226,8 +242,10 @@ void main() { ); expect( - log.last, - isMethodCall('periodicallyShow', arguments: { + log.last, + isMethodCall( + 'periodicallyShow', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -250,13 +268,15 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, 'criticalSoundVolume': null, }, - })); + }, + ), + ); }); }); } @@ -272,8 +292,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( @@ -288,21 +309,22 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); expect( - () async => await flutterLocalNotificationsPlugin - .periodicallyShowWithDuration( - 1, - 'notification title', - 'notification body', - thirtySeconds, - notificationDetails, - ), - throwsA(isA())); + () async => await flutterLocalNotificationsPlugin + .periodicallyShowWithDuration( + 1, + 'notification title', + 'notification body', + thirtySeconds, + notificationDetails, + ), + throwsA(isA()), + ); }); }); @@ -310,7 +332,7 @@ void main() { const Duration(minutes: 1), const Duration(minutes: 15), const Duration(hours: 5), - const Duration(days: 30) + const Duration(days: 30), ]; for (final Duration repeatDurationInterval in repeatDurationIntervals) { @@ -320,8 +342,9 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( @@ -336,7 +359,7 @@ void main() { DarwinNotificationAttachment( 'video.mp4', identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', - ) + ), ], ), ); @@ -350,40 +373,42 @@ void main() { ); expect( - log.last, - isMethodCall('periodicallyShowWithDuration', - arguments: { - 'id': 1, - 'title': 'notification title', - 'body': 'notification body', - 'payload': '', - 'calledAt': now.millisecondsSinceEpoch, - 'repeatIntervalMilliseconds': - repeatDurationInterval.inMilliseconds, - 'platformSpecifics': { - 'presentAlert': true, - 'presentBadge': true, - 'presentSound': true, - 'presentBanner': true, - 'presentList': true, - 'subtitle': null, - 'sound': 'sound.mp3', - 'badgeNumber': 1, - 'threadIdentifier': null, - 'attachments': >[ - { - 'filePath': 'video.mp4', - 'identifier': - '2b3f705f-a680-4c9f-8075-a46a70e28373', - 'hideThumbnail': null, - 'thumbnailClippingRect': null, - } - ], - 'categoryIdentifier': null, - 'interruptionLevel': null, - 'criticalSoundVolume': null, + log.last, + isMethodCall( + 'periodicallyShowWithDuration', + arguments: { + 'id': 1, + 'title': 'notification title', + 'body': 'notification body', + 'payload': '', + 'calledAt': now.millisecondsSinceEpoch, + 'repeatIntervalMilliseconds': + repeatDurationInterval.inMilliseconds, + 'platformSpecifics': { + 'presentAlert': true, + 'presentBadge': true, + 'presentSound': true, + 'presentBanner': true, + 'presentList': true, + 'subtitle': null, + 'sound': 'sound.mp3', + 'badgeNumber': 1, + 'threadIdentifier': null, + 'attachments': >[ + { + 'filePath': 'video.mp4', + 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', + 'hideThumbnail': null, + 'thumbnailClippingRect': null, }, - })); + ], + 'categoryIdentifier': null, + 'interruptionLevel': null, + 'criticalSoundVolume': null, + }, + }, + ), + ); }); }); } @@ -395,12 +420,14 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( presentAlert: true, @@ -411,23 +438,28 @@ void main() { sound: 'sound.mp3', badgeNumber: 1, attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), ], ), ); await flutterLocalNotificationsPlugin.zonedSchedule( - 1, - 'notification title', - 'notification body', - scheduledDate, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle); + 1, + 'notification title', + 'notification body', + scheduledDate, + notificationDetails, + androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, + ); expect( - log.last, - isMethodCall('zonedSchedule', arguments: { + log.last, + isMethodCall( + 'zonedSchedule', + arguments: { 'id': 1, 'title': 'notification title', 'body': 'notification body', @@ -451,13 +483,15 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, 'criticalSoundVolume': null, }, - })); + }, + ), + ); }); test('match time components', () async { @@ -465,12 +499,14 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( presentAlert: true, @@ -481,8 +517,10 @@ void main() { sound: 'sound.mp3', badgeNumber: 1, attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), ], ), ); @@ -526,7 +564,7 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, @@ -542,12 +580,14 @@ void main() { DarwinInitializationSettings(); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); - await flutterLocalNotificationsPlugin - .initialize(initializationSettings); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); tz.initializeTimeZones(); tz.setLocalLocation(tz.getLocation('Australia/Sydney')); - final tz.TZDateTime scheduledDate = - tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)); + final tz.TZDateTime scheduledDate = tz.TZDateTime.now( + tz.local, + ).add(const Duration(seconds: 5)); const NotificationDetails notificationDetails = NotificationDetails( macOS: DarwinNotificationDetails( presentAlert: true, @@ -558,8 +598,10 @@ void main() { sound: 'sound.mp3', badgeNumber: 1, attachments: [ - DarwinNotificationAttachment('video.mp4', - identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373') + DarwinNotificationAttachment( + 'video.mp4', + identifier: '2b3f705f-a680-4c9f-8075-a46a70e28373', + ), ], ), ); @@ -604,7 +646,7 @@ void main() { 'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373', 'hideThumbnail': null, 'thumbnailClippingRect': null, - } + }, ], 'categoryIdentifier': null, 'interruptionLevel': null, @@ -619,23 +661,28 @@ void main() { test('requestPermissions with default settings', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>()! + MacOSFlutterLocalNotificationsPlugin + >()! .requestPermissions(); expect(log, [ - isMethodCall('requestPermissions', arguments: { - 'sound': false, - 'badge': false, - 'alert': false, - 'provisional': false, - 'critical': false, - 'providesAppNotificationSettings': false - }) + isMethodCall( + 'requestPermissions', + arguments: { + 'sound': false, + 'badge': false, + 'alert': false, + 'provisional': false, + 'critical': false, + 'providesAppNotificationSettings': false, + }, + ), ]); }); test('requestPermissions with all settings requested', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>()! + MacOSFlutterLocalNotificationsPlugin + >()! .requestPermissions( sound: true, badge: true, @@ -643,25 +690,26 @@ void main() { provisional: true, critical: true, ); - expect( - log, - [ - isMethodCall('requestPermissions', arguments: { + expect(log, [ + isMethodCall( + 'requestPermissions', + arguments: { 'sound': true, 'badge': true, 'alert': true, 'provisional': true, 'critical': true, 'providesAppNotificationSettings': false, - }) - ], - ); + }, + ), + ]); }); test('checkPermissions', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>()! + MacOSFlutterLocalNotificationsPlugin + >()! .checkPermissions(); expect(log, [isMethodCall('checkPermissions', arguments: null)]); }); @@ -679,35 +727,36 @@ void main() { test('cancelAllPendingNotifications', () async { await flutterLocalNotificationsPlugin.cancelAllPendingNotifications(); expect(log, [ - isMethodCall('cancelAllPendingNotifications', arguments: null) + isMethodCall('cancelAllPendingNotifications', arguments: null), ]); }); test('pendingNotificationRequests', () async { await flutterLocalNotificationsPlugin.pendingNotificationRequests(); expect(log, [ - isMethodCall('pendingNotificationRequests', arguments: null) + isMethodCall('pendingNotificationRequests', arguments: null), ]); }); test('getActiveNotifications', () async { await flutterLocalNotificationsPlugin.getActiveNotifications(); - expect(log, - [isMethodCall('getActiveNotifications', arguments: null)]); + expect(log, [ + isMethodCall('getActiveNotifications', arguments: null), + ]); }); test('getNotificationAppLaunchDetails', () async { await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); expect(log, [ - isMethodCall('getNotificationAppLaunchDetails', arguments: null) + isMethodCall('getNotificationAppLaunchDetails', arguments: null), ]); }); test('initialize with providesAppNotificationSettings', () async { const DarwinInitializationSettings macOSInitializationSettings = DarwinInitializationSettings( - requestProvidesAppNotificationSettings: true, - ); + requestProvidesAppNotificationSettings: true, + ); const InitializationSettings initializationSettings = InitializationSettings(macOS: macOSInitializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings); @@ -735,7 +784,8 @@ void main() { test('requestPermissions with providesAppNotificationSettings', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>() + MacOSFlutterLocalNotificationsPlugin + >() ?.requestPermissions( alert: true, badge: true, @@ -760,7 +810,8 @@ void main() { test('macOS requestPermissions with all settings requested', () async { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< - MacOSFlutterLocalNotificationsPlugin>()! + MacOSFlutterLocalNotificationsPlugin + >()! .requestPermissions( sound: true, badge: true, @@ -770,14 +821,17 @@ void main() { providesAppNotificationSettings: true, ); expect(log, [ - isMethodCall('requestPermissions', arguments: { - 'sound': true, - 'alert': true, - 'badge': true, - 'provisional': true, - 'critical': true, - 'providesAppNotificationSettings': true - }) + isMethodCall( + 'requestPermissions', + arguments: { + 'sound': true, + 'alert': true, + 'badge': true, + 'provisional': true, + 'critical': true, + 'providesAppNotificationSettings': true, + }, + ), ]); }); }); diff --git a/flutter_local_notifications/test/platform_specifics/darwin/mappers_test.dart b/flutter_local_notifications/test/platform_specifics/darwin/mappers_test.dart index 090dd4e38..55a7a94a4 100644 --- a/flutter_local_notifications/test/platform_specifics/darwin/mappers_test.dart +++ b/flutter_local_notifications/test/platform_specifics/darwin/mappers_test.dart @@ -11,11 +11,15 @@ void main() { group('DarwinNotificationActionMapper', () { test('should map fields and options correctly', () { expect( - DarwinNotificationAction.plain('test_id', 'Something', options: { - DarwinNotificationActionOption.authenticationRequired, - DarwinNotificationActionOption.destructive, - DarwinNotificationActionOption.foreground, - }).toMap(), + DarwinNotificationAction.plain( + 'test_id', + 'Something', + options: { + DarwinNotificationActionOption.authenticationRequired, + DarwinNotificationActionOption.destructive, + DarwinNotificationActionOption.foreground, + }, + ).toMap(), { 'identifier': 'test_id', 'title': 'Something', @@ -29,13 +33,16 @@ void main() { group('DarwinNotificationCategoryMapper', () { test('should map fields and options correctly', () { expect( - const DarwinNotificationCategory('test_id', options: { - DarwinNotificationCategoryOption.customDismissAction, - DarwinNotificationCategoryOption.allowInCarPlay, - DarwinNotificationCategoryOption.hiddenPreviewShowTitle, - DarwinNotificationCategoryOption.hiddenPreviewShowSubtitle, - DarwinNotificationCategoryOption.allowAnnouncement, - }).toMap(), + const DarwinNotificationCategory( + 'test_id', + options: { + DarwinNotificationCategoryOption.customDismissAction, + DarwinNotificationCategoryOption.allowInCarPlay, + DarwinNotificationCategoryOption.hiddenPreviewShowTitle, + DarwinNotificationCategoryOption.hiddenPreviewShowSubtitle, + DarwinNotificationCategoryOption.allowAnnouncement, + }, + ).toMap(), { 'identifier': 'test_id', 'actions': [], diff --git a/flutter_local_notifications_linux/lib/src/dbus_wrapper.dart b/flutter_local_notifications_linux/lib/src/dbus_wrapper.dart index 95237941c..6c1626dd6 100644 --- a/flutter_local_notifications_linux/lib/src/dbus_wrapper.dart +++ b/flutter_local_notifications_linux/lib/src/dbus_wrapper.dart @@ -8,10 +8,7 @@ class DBusWrapper { late final String _destination; /// Build an instance of [DBusRemoteObject] - void build({ - required String destination, - required String path, - }) { + void build({required String destination, required String path}) { _destination = destination; _object = DBusRemoteObject( DBusClient.session(), @@ -34,19 +31,21 @@ class DBusWrapper { bool noReplyExpected = false, bool noAutoStart = false, bool allowInteractiveAuthorization = false, - }) => - _object.callMethod( - interface, - name, - values, - replySignature: replySignature, - noReplyExpected: noReplyExpected, - noAutoStart: noAutoStart, - allowInteractiveAuthorization: allowInteractiveAuthorization, - ); + }) => _object.callMethod( + interface, + name, + values, + replySignature: replySignature, + noReplyExpected: noReplyExpected, + noAutoStart: noAutoStart, + allowInteractiveAuthorization: allowInteractiveAuthorization, + ); /// Creates a stream of signal with the given [name]. DBusRemoteObjectSignalStream subscribeSignal(String name) => DBusRemoteObjectSignalStream( - object: _object, interface: _destination, name: name); + object: _object, + interface: _destination, + name: name, + ); } diff --git a/flutter_local_notifications_linux/lib/src/flutter_local_notifications.dart b/flutter_local_notifications_linux/lib/src/flutter_local_notifications.dart index f75169669..19c56466a 100644 --- a/flutter_local_notifications_linux/lib/src/flutter_local_notifications.dart +++ b/flutter_local_notifications_linux/lib/src/flutter_local_notifications.dart @@ -11,14 +11,13 @@ class LinuxFlutterLocalNotificationsPlugin extends FlutterLocalNotificationsPlatformLinux { /// Constructs an instance of [LinuxNotificationDetails]. LinuxFlutterLocalNotificationsPlugin() - : _manager = LinuxNotificationManager(); + : _manager = LinuxNotificationManager(); /// Constructs an instance of [LinuxNotificationDetails] /// with the give [manager]. @visibleForTesting - LinuxFlutterLocalNotificationsPlugin.private( - LinuxNotificationManager manager, - ) : _manager = manager; + LinuxFlutterLocalNotificationsPlugin.private(LinuxNotificationManager manager) + : _manager = manager; /// Registers the Linux implementation. static void registerWith() { @@ -42,11 +41,10 @@ class LinuxFlutterLocalNotificationsPlugin Future initialize( LinuxInitializationSettings initializationSettings, { DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse, - }) => - _manager.initialize( - initializationSettings, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - ); + }) => _manager.initialize( + initializationSettings, + onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, + ); /// Show a notification with an optional payload that will be passed back to /// the app when a notification is tapped on. diff --git a/flutter_local_notifications_linux/lib/src/helpers.dart b/flutter_local_notifications_linux/lib/src/helpers.dart index ef2c9503d..f0f3e57ba 100644 --- a/flutter_local_notifications_linux/lib/src/helpers.dart +++ b/flutter_local_notifications_linux/lib/src/helpers.dart @@ -27,9 +27,9 @@ extension LinuxHintValueExtension on LinuxHintValue { m.map( (LinuxHintValue key, LinuxHintValue value) => MapEntry( - key.toDBusValue(), - value.toDBusValue(), - ), + key.toDBusValue(), + value.toDBusValue(), + ), ), ); case LinuxHintValueType.double: diff --git a/flutter_local_notifications_linux/lib/src/model/capabilities.dart b/flutter_local_notifications_linux/lib/src/model/capabilities.dart index 880f6f329..91bc4b56d 100644 --- a/flutter_local_notifications_linux/lib/src/model/capabilities.dart +++ b/flutter_local_notifications_linux/lib/src/model/capabilities.dart @@ -129,23 +129,23 @@ class LinuxServerCapabilities { bool? sound, bool? actions, bool? actionIcons, - }) => - LinuxServerCapabilities( - otherCapabilities: otherCapabilities ?? this.otherCapabilities, - body: body ?? this.body, - bodyHyperlinks: bodyHyperlinks ?? this.bodyHyperlinks, - bodyImages: bodyImages ?? this.bodyImages, - bodyMarkup: bodyMarkup ?? this.bodyMarkup, - iconMulti: iconMulti ?? this.iconMulti, - iconStatic: iconStatic ?? this.iconStatic, - persistence: persistence ?? this.persistence, - sound: sound ?? this.sound, - actions: actions ?? this.actions, - actionIcons: actionIcons ?? this.actionIcons, - ); + }) => LinuxServerCapabilities( + otherCapabilities: otherCapabilities ?? this.otherCapabilities, + body: body ?? this.body, + bodyHyperlinks: bodyHyperlinks ?? this.bodyHyperlinks, + bodyImages: bodyImages ?? this.bodyImages, + bodyMarkup: bodyMarkup ?? this.bodyMarkup, + iconMulti: iconMulti ?? this.iconMulti, + iconStatic: iconStatic ?? this.iconStatic, + persistence: persistence ?? this.persistence, + sound: sound ?? this.sound, + actions: actions ?? this.actions, + actionIcons: actionIcons ?? this.actionIcons, + ); @override - String toString() => 'LinuxServerCapabilities(otherCapabilities: ' + String toString() => + 'LinuxServerCapabilities(otherCapabilities: ' '$otherCapabilities, body: $body, bodyHyperlinks: $bodyHyperlinks, ' 'bodyImages: $bodyImages, bodyMarkup: $bodyMarkup, ' 'iconMulti: $iconMulti, iconStatic: $iconStatic, ' diff --git a/flutter_local_notifications_linux/lib/src/model/enums.dart b/flutter_local_notifications_linux/lib/src/model/enums.dart index 5dc3fa947..7912fd9fb 100644 --- a/flutter_local_notifications_linux/lib/src/model/enums.dart +++ b/flutter_local_notifications_linux/lib/src/model/enums.dart @@ -94,7 +94,7 @@ enum LinuxNotificationUrgency { normal, /// Critical urgency. Used for very important notifications. - critical + critical, } /// Specifies the Linux notification icon type. diff --git a/flutter_local_notifications_linux/lib/src/model/hint.dart b/flutter_local_notifications_linux/lib/src/model/hint.dart index 60c27d441..cd554ceb6 100644 --- a/flutter_local_notifications_linux/lib/src/model/hint.dart +++ b/flutter_local_notifications_linux/lib/src/model/hint.dart @@ -74,12 +74,10 @@ class LinuxHintDictValue /// Constructs an instance of [LinuxHintDictValue]. LinuxHintDictValue.stringVariant(Map value) - : value = value.map( - (String key, V value) => MapEntry( - LinuxHintStringValue(key) as K, - value, - ), - ); + : value = value.map( + (String key, V value) => + MapEntry(LinuxHintStringValue(key) as K, value), + ); @override LinuxHintValueType get type => LinuxHintValueType.dict; diff --git a/flutter_local_notifications_linux/lib/src/model/location.dart b/flutter_local_notifications_linux/lib/src/model/location.dart index bfbb9216d..43589eef1 100644 --- a/flutter_local_notifications_linux/lib/src/model/location.dart +++ b/flutter_local_notifications_linux/lib/src/model/location.dart @@ -16,10 +16,7 @@ class LinuxNotificationLocation { /// Creates a copy of this object, /// but with the given fields replaced with the new values. - LinuxNotificationLocation copyWith({ - int? x, - int? y, - }) => + LinuxNotificationLocation copyWith({int? x, int? y}) => LinuxNotificationLocation(x ?? this.x, y ?? this.y); @override diff --git a/flutter_local_notifications_linux/lib/src/model/notification_details.dart b/flutter_local_notifications_linux/lib/src/model/notification_details.dart index 8898c9edc..f51aaa7f0 100644 --- a/flutter_local_notifications_linux/lib/src/model/notification_details.dart +++ b/flutter_local_notifications_linux/lib/src/model/notification_details.dart @@ -101,10 +101,7 @@ class LinuxNotificationDetails { /// For more information, please see Desktop Notifications Specification https://specifications.freedesktop.org/notification-spec/latest/ar01s02.html class LinuxNotificationAction { /// Constructs a [LinuxNotificationAction] object. - const LinuxNotificationAction({ - required this.key, - required this.label, - }); + const LinuxNotificationAction({required this.key, required this.label}); /// Unique ID for this action. This ID will be sent back in the action handler /// defined in [FlutterLocalNotificationsPlugin]. diff --git a/flutter_local_notifications_linux/lib/src/model/timeout.dart b/flutter_local_notifications_linux/lib/src/model/timeout.dart index ff2392909..9a8da1a35 100644 --- a/flutter_local_notifications_linux/lib/src/model/timeout.dart +++ b/flutter_local_notifications_linux/lib/src/model/timeout.dart @@ -10,7 +10,7 @@ class LinuxNotificationTimeout { /// Constructs an instance of [LinuxNotificationTimeout] /// with a given [Duration] value. LinuxNotificationTimeout.fromDuration(Duration duration) - : value = duration.inMilliseconds; + : value = duration.inMilliseconds; /// Constructs an instance of [LinuxNotificationTimeout] /// with a [value] equal to `-1`. diff --git a/flutter_local_notifications_linux/lib/src/notification_info.dart b/flutter_local_notifications_linux/lib/src/notification_info.dart index b89d9afb1..b5833eeb9 100644 --- a/flutter_local_notifications_linux/lib/src/notification_info.dart +++ b/flutter_local_notifications_linux/lib/src/notification_info.dart @@ -16,8 +16,11 @@ class LinuxNotificationInfo { final List? actionsJson = json['actions'] as List?; final List? actions = actionsJson // ignore: avoid_annotating_with_dynamic - ?.map((dynamic json) => - LinuxNotificationActionInfo.fromJson(json as Map)) + ?.map( + (dynamic json) => LinuxNotificationActionInfo.fromJson( + json as Map, + ), + ) .toList(); return LinuxNotificationInfo( id: json['id'] as int, @@ -43,12 +46,13 @@ class LinuxNotificationInfo { /// Returns the object as a key-value map Map toJson() => { - 'id': id, - 'systemId': systemId, - 'payload': payload, - 'actions': - actions.map((LinuxNotificationActionInfo a) => a.toJson()).toList(), - }; + 'id': id, + 'systemId': systemId, + 'payload': payload, + 'actions': actions + .map((LinuxNotificationActionInfo a) => a.toJson()) + .toList(), + }; /// Creates a copy of this object, /// but with the given fields replaced with the new values. @@ -57,13 +61,12 @@ class LinuxNotificationInfo { int? systemId, String? payload, List? actions, - }) => - LinuxNotificationInfo( - id: id ?? this.id, - systemId: systemId ?? this.systemId, - payload: payload ?? this.payload, - actions: actions ?? this.actions, - ); + }) => LinuxNotificationInfo( + id: id ?? this.id, + systemId: systemId ?? this.systemId, + payload: payload ?? this.payload, + actions: actions ?? this.actions, + ); @override bool operator ==(Object other) { @@ -87,9 +90,7 @@ class LinuxNotificationInfo { @immutable class LinuxNotificationActionInfo { /// Constructs an instance of [LinuxNotificationActionInfo]. - const LinuxNotificationActionInfo({ - required this.key, - }); + const LinuxNotificationActionInfo({required this.key}); /// Constructs an instance of [LinuxNotificationActionInfo] from [json]. factory LinuxNotificationActionInfo.fromJson(Map json) => @@ -103,10 +104,7 @@ class LinuxNotificationActionInfo { /// Creates a copy of this object, /// but with the given fields replaced with the new values. - LinuxNotificationActionInfo copyWith({ - String? key, - String? payload, - }) => + LinuxNotificationActionInfo copyWith({String? key, String? payload}) => LinuxNotificationActionInfo(key: key ?? this.key); @override diff --git a/flutter_local_notifications_linux/lib/src/notifications_manager.dart b/flutter_local_notifications_linux/lib/src/notifications_manager.dart index 0fe413ced..30a3e811b 100644 --- a/flutter_local_notifications_linux/lib/src/notifications_manager.dart +++ b/flutter_local_notifications_linux/lib/src/notifications_manager.dart @@ -24,9 +24,9 @@ import 'storage.dart'; class LinuxNotificationManager { /// Constructs an instance of of [LinuxNotificationManager] LinuxNotificationManager() - : _dbus = DBusWrapper(), - _platformInfo = LinuxPlatformInfo(), - _storage = NotificationStorage(); + : _dbus = DBusWrapper(), + _platformInfo = LinuxPlatformInfo(), + _storage = NotificationStorage(); /// Constructs an instance of of [LinuxNotificationManager] /// with the given class dependencies. @@ -35,9 +35,9 @@ class LinuxNotificationManager { DBusWrapper? dbus, LinuxPlatformInfo? platformInfo, NotificationStorage? storage, - }) : _dbus = dbus ?? DBusWrapper(), - _platformInfo = platformInfo ?? LinuxPlatformInfo(), - _storage = storage ?? NotificationStorage(); + }) : _dbus = dbus ?? DBusWrapper(), + _platformInfo = platformInfo ?? LinuxPlatformInfo(), + _storage = storage ?? NotificationStorage(); final DBusWrapper _dbus; final LinuxPlatformInfo _platformInfo; @@ -45,7 +45,7 @@ class LinuxNotificationManager { late final LinuxInitializationSettings _initializationSettings; late final DidReceiveNotificationResponseCallback? - _onDidReceiveNotificationResponse; + _onDidReceiveNotificationResponse; late final LinuxPlatformInfoData _platformData; bool _initialized = false; @@ -113,14 +113,14 @@ class LinuxNotificationManager { ); final List? actionsInfo = details?.actions .map( - (LinuxNotificationAction action) => LinuxNotificationActionInfo( - key: action.key, - ), + (LinuxNotificationAction action) => + LinuxNotificationActionInfo(key: action.key), ) .toList(); final int systemId = (result.returnValues[0] as DBusUint32).value; - final LinuxNotificationInfo notify = prevNotify?.copyWith( + final LinuxNotificationInfo notify = + prevNotify?.copyWith( systemId: systemId, payload: payload, actions: actionsInfo, @@ -143,17 +143,15 @@ class LinuxNotificationManager { details?.icon ?? initSettings.defaultIcon; if (icon?.type == LinuxIconType.byteData) { final LinuxRawIconData data = icon!.content as LinuxRawIconData; - hints['image-data'] = DBusStruct( - [ - DBusInt32(data.width), - DBusInt32(data.height), - DBusInt32(data.rowStride), - DBusBoolean(data.hasAlpha), - DBusInt32(data.bitsPerSample), - DBusInt32(data.channels), - DBusArray.byte(data.data), - ], - ); + hints['image-data'] = DBusStruct([ + DBusInt32(data.width), + DBusInt32(data.height), + DBusInt32(data.rowStride), + DBusBoolean(data.hasAlpha), + DBusInt32(data.bitsPerSample), + DBusInt32(data.channels), + DBusArray.byte(data.data), + ]); } final LinuxNotificationSound? sound = details?.sound ?? initSettings.defaultSound; @@ -161,10 +159,7 @@ class LinuxNotificationManager { switch (sound.type) { case LinuxSoundType.assets: hints['sound-file'] = DBusString( - path.join( - _platformData.assetsPath!, - sound.content as String, - ), + path.join(_platformData.assetsPath!, sound.content as String), ); break; case LinuxSoundType.theme: @@ -206,15 +201,12 @@ class LinuxNotificationManager { Map _buildCustomHints( List hints, - ) => - Map.fromEntries( - hints.map( - (LinuxNotificationCustomHint hint) => MapEntry( - hint.name, - hint.value.toDBusValue(), - ), - ), - ); + ) => Map.fromEntries( + hints.map( + (LinuxNotificationCustomHint hint) => + MapEntry(hint.name, hint.value.toDBusValue()), + ), + ); List _buildActions( LinuxNotificationDetails? details, @@ -263,8 +255,7 @@ class LinuxNotificationManager { [], replySignature: DBusSignature('as'), ); - final Set capsSet = (result.returnValues[0] as DBusArray) - .children + final Set capsSet = (result.returnValues[0] as DBusArray).children .map((DBusValue c) => (c as DBusString).value) .toSet(); @@ -286,22 +277,21 @@ class LinuxNotificationManager { /// Returns a [Map] with the specified notification id as the key /// and the id, assigned by the system, as the value. - Future> getSystemIdMap() async => - Map.fromEntries(await _storage.getAll().then( - (List list) => list.map( - (LinuxNotificationInfo notify) => MapEntry( - notify.id, - notify.systemId, - ), - ), - )); + Future> getSystemIdMap() async => Map.fromEntries( + await _storage.getAll().then( + (List list) => list.map( + (LinuxNotificationInfo notify) => + MapEntry(notify.id, notify.systemId), + ), + ), + ); Future _dbusCancel(int systemId) => _dbus.callMethod( - _DBusInterfaceSpec.destination, - _DBusMethodsSpec.closeNotification, - [DBusUint32(systemId)], - replySignature: DBusSignature(''), - ); + _DBusInterfaceSpec.destination, + _DBusMethodsSpec.closeNotification, + [DBusUint32(systemId)], + replySignature: DBusSignature(''), + ); String? _getAppIcon(LinuxNotificationIcon? icon) { if (icon == null) { @@ -326,59 +316,58 @@ class LinuxNotificationManager { /// Subscribe to the signals for actions and closing notifications. void _subscribeSignals() { - _dbus.subscribeSignal(_DBusMethodsSpec.actionInvoked).listen( - (DBusSignal s) async { - if (s.signature != DBusSignature('us')) { - return; - } + _dbus.subscribeSignal(_DBusMethodsSpec.actionInvoked).listen(( + DBusSignal s, + ) async { + if (s.signature != DBusSignature('us')) { + return; + } - final int systemId = (s.values[0] as DBusUint32).value; - final String actionKey = (s.values[1] as DBusString).value; - final LinuxNotificationInfo? notify = - await _storage.getBySystemId(systemId); - if (notify == null) { + final int systemId = (s.values[0] as DBusUint32).value; + final String actionKey = (s.values[1] as DBusString).value; + final LinuxNotificationInfo? notify = await _storage.getBySystemId( + systemId, + ); + if (notify == null) { + return; + } + if (actionKey == _kDefaultActionName) { + _onDidReceiveNotificationResponse?.call( + NotificationResponse( + id: notify.id, + payload: notify.payload, + notificationResponseType: + NotificationResponseType.selectedNotification, + ), + ); + } else { + final LinuxNotificationActionInfo? actionInfo = notify.actions + .firstWhere((LinuxNotificationActionInfo a) => a.key == actionKey); + if (actionInfo == null) { return; } - if (actionKey == _kDefaultActionName) { - _onDidReceiveNotificationResponse?.call( - NotificationResponse( - id: notify.id, - payload: notify.payload, - notificationResponseType: - NotificationResponseType.selectedNotification, - ), - ); - } else { - final LinuxNotificationActionInfo? actionInfo = - notify.actions.firstWhere( - (LinuxNotificationActionInfo a) => a.key == actionKey, - ); - if (actionInfo == null) { - return; - } - _onDidReceiveNotificationResponse?.call( - NotificationResponse( - id: notify.id, - actionId: actionInfo.key, - payload: notify.payload, - notificationResponseType: - NotificationResponseType.selectedNotificationAction, - ), - ); - } - }, - ); + _onDidReceiveNotificationResponse?.call( + NotificationResponse( + id: notify.id, + actionId: actionInfo.key, + payload: notify.payload, + notificationResponseType: + NotificationResponseType.selectedNotificationAction, + ), + ); + } + }); - _dbus.subscribeSignal(_DBusMethodsSpec.notificationClosed).listen( - (DBusSignal s) async { - if (s.signature != DBusSignature('uu')) { - return; - } + _dbus.subscribeSignal(_DBusMethodsSpec.notificationClosed).listen(( + DBusSignal s, + ) async { + if (s.signature != DBusSignature('uu')) { + return; + } - final int systemId = (s.values[0] as DBusUint32).value; - await _storage.removeBySystemId(systemId); - }, - ); + final int systemId = (s.values[0] as DBusUint32).value; + await _storage.removeBySystemId(systemId); + }); } } diff --git a/flutter_local_notifications_linux/lib/src/platform_info.dart b/flutter_local_notifications_linux/lib/src/platform_info.dart index 08d6ecfb8..b9e2d6ac2 100644 --- a/flutter_local_notifications_linux/lib/src/platform_info.dart +++ b/flutter_local_notifications_linux/lib/src/platform_info.dart @@ -13,8 +13,9 @@ class LinuxPlatformInfo { /// Returns all platform-specific info Future getAll() async { try { - final String exePath = - await File('/proc/self/exe').resolveSymbolicLinks(); + final String exePath = await File( + '/proc/self/exe', + ).resolveSymbolicLinks(); final String processName = path.basenameWithoutExtension(exePath); final String appPath = path.dirname(exePath); final String assetPath = path.join(appPath, 'data', 'flutter_assets'); diff --git a/flutter_local_notifications_linux/lib/src/storage.dart b/flutter_local_notifications_linux/lib/src/storage.dart index 3bba1ed72..4d2b2851a 100644 --- a/flutter_local_notifications_linux/lib/src/storage.dart +++ b/flutter_local_notifications_linux/lib/src/storage.dart @@ -15,11 +15,9 @@ const String _kFileName = 'notification_plugin_cache.json'; /// The storage data exists within the user session. class NotificationStorage { /// Constructs an instance of of [NotificationStorageImpl]. - NotificationStorage({ - LinuxPlatformInfo? platformInfo, - FileSystem? fs, - }) : _platformInfo = platformInfo ?? LinuxPlatformInfo(), - _fs = fs ?? LocalFileSystem(); + NotificationStorage({LinuxPlatformInfo? platformInfo, FileSystem? fs}) + : _platformInfo = platformInfo ?? LinuxPlatformInfo(), + _fs = fs ?? LocalFileSystem(); final LinuxPlatformInfo _platformInfo; final FileSystem _fs; @@ -114,8 +112,9 @@ class NotificationStorage { final dynamic json = jsonDecode(jsonStr); if (json is List) { for (final dynamic j in json) { - final LinuxNotificationInfo info = - LinuxNotificationInfo.fromJson(j); + final LinuxNotificationInfo info = LinuxNotificationInfo.fromJson( + j, + ); cache.insert(info); } } else { @@ -149,8 +148,8 @@ class NotificationStorage { class _Cache { _Cache() - : _infoMap = {}, - _systemIdMap = {}; + : _infoMap = {}, + _systemIdMap = {}; final Map _infoMap; diff --git a/flutter_local_notifications_linux/test/notifications_manager_test.dart b/flutter_local_notifications_linux/test/notifications_manager_test.dart index 4e89c0620..7a32cb647 100644 --- a/flutter_local_notifications_linux/test/notifications_manager_test.dart +++ b/flutter_local_notifications_linux/test/notifications_manager_test.dart @@ -43,7 +43,7 @@ void main() { late final MockLinuxPlatformInfo mockPlatformInfo; late final MockNotificationStorage mockStorage; late final MockDidReceiveNotificationResponseCallback - mockDidReceiveNotificationResponseCallback; + mockDidReceiveNotificationResponseCallback; const LinuxPlatformInfoData platformInfo = LinuxPlatformInfoData( appName: 'Test', @@ -60,12 +60,8 @@ void main() { mockDidReceiveNotificationResponseCallback = MockDidReceiveNotificationResponseCallback(); - when( - mockPlatformInfo.getAll(), - ).thenAnswer((_) async => platformInfo); - when( - mockStorage.forceReloadCache(), - ).thenAnswer((_) async {}); + when(mockPlatformInfo.getAll()).thenAnswer((_) async => platformInfo); + when(mockStorage.forceReloadCache()).thenAnswer((_) async {}); when( mockDbus.build( destination: 'org.freedesktop.Notifications', @@ -99,30 +95,26 @@ void main() { }); void mockCloseMethod() => when( - mockDbus.callMethod( - 'org.freedesktop.Notifications', - 'CloseNotification', - any, - replySignature: DBusSignature(''), - ), - ).thenAnswer( - (_) async => DBusMethodSuccessResponse(), - ); + mockDbus.callMethod( + 'org.freedesktop.Notifications', + 'CloseNotification', + any, + replySignature: DBusSignature(''), + ), + ).thenAnswer((_) async => DBusMethodSuccessResponse()); VerificationResult verifyCloseMethod(int systemId) => verify( - mockDbus.callMethod( - 'org.freedesktop.Notifications', - 'CloseNotification', - [DBusUint32(systemId)], - replySignature: DBusSignature(''), - ), - ); + mockDbus.callMethod( + 'org.freedesktop.Notifications', + 'CloseNotification', + [DBusUint32(systemId)], + replySignature: DBusSignature(''), + ), + ); test('Initialize', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: 'test', - ); + LinuxInitializationSettings(defaultActionName: 'test'); await manager.initialize(initSettings); @@ -149,31 +141,29 @@ void main() { List? actions, Map? hints, int? expireTimeout, - }) => - [ - // app_name - DBusString(platformInfo.appName!), - // replaces_id - DBusUint32(replacesId ?? 0), - // app_icon - DBusString(appIcon ?? ''), - // summary - DBusString(title ?? ''), - // body - DBusString(body ?? ''), - // actions - DBusArray.string( - ['default', kDefaultActionName, ...?actions]), - // hints - DBusDict.stringVariant(hints ?? {}), - // expire_timeout - DBusInt32( - expireTimeout ?? - const LinuxNotificationTimeout.systemDefault().value, - ), - ]; + }) => [ + // app_name + DBusString(platformInfo.appName!), + // replaces_id + DBusUint32(replacesId ?? 0), + // app_icon + DBusString(appIcon ?? ''), + // summary + DBusString(title ?? ''), + // body + DBusString(body ?? ''), + // actions + DBusArray.string(['default', kDefaultActionName, ...?actions]), + // hints + DBusDict.stringVariant(hints ?? {}), + // expire_timeout + DBusInt32( + expireTimeout ?? const LinuxNotificationTimeout.systemDefault().value, + ), + ]; - void mockNotifyMethod(int systemId) => when( + void mockNotifyMethod(int systemId) => + when( mockDbus.callMethod( 'org.freedesktop.Notifications', 'Notify', @@ -181,18 +171,18 @@ void main() { replySignature: DBusSignature('u'), ), ).thenAnswer( - (_) async => DBusMethodSuccessResponse( - [DBusUint32(systemId)], - ), + (_) async => + DBusMethodSuccessResponse([DBusUint32(systemId)]), ); - VerificationResult verifyNotifyMethod(List values) => - verify(mockDbus.callMethod( - 'org.freedesktop.Notifications', - 'Notify', - values, - replySignature: DBusSignature('u'), - )); + VerificationResult verifyNotifyMethod(List values) => verify( + mockDbus.callMethod( + 'org.freedesktop.Notifications', + 'Notify', + values, + replySignature: DBusSignature('u'), + ), + ); test('Simple notification', () async { const LinuxInitializationSettings initSettings = @@ -209,20 +199,14 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, 'Title', 'Body'); verifyNotifyMethod(values).called(1); - verify( - mockStorage.insert(notify), - ).called(1); + verify(mockStorage.insert(notify)).called(1); }); test('Simple notification without title and body', () async { @@ -237,20 +221,14 @@ void main() { final List values = buildNotifyMethodValues(); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null); verifyNotifyMethod(values).called(1); - verify( - mockStorage.insert(notify), - ).called(1); + verify(mockStorage.insert(notify)).called(1); }); test('Replace previous notification', () async { @@ -278,25 +256,21 @@ void main() { when( mockStorage.getById(newNotify.id), ).thenAnswer((_) async => prevNotify); - when( - mockStorage.insert(newNotify), - ).thenAnswer((_) async => true); + when(mockStorage.insert(newNotify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(newNotify.id, 'Title', 'Body'); verifyNotifyMethod(values).called(1); - verify( - mockStorage.insert(newNotify), - ).called(1); + verify(mockStorage.insert(newNotify)).called(1); }); test('Assets details icon', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultIcon: AssetsLinuxIcon('icon.png'), - ); + defaultActionName: kDefaultActionName, + defaultIcon: AssetsLinuxIcon('icon.png'), + ); final LinuxNotificationDetails details = LinuxNotificationDetails( icon: AssetsLinuxIcon('details_icon.png'), @@ -312,12 +286,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -328,16 +298,12 @@ void main() { test('Byte details icon', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultIcon: AssetsLinuxIcon('icon.png'), - ); + defaultActionName: kDefaultActionName, + defaultIcon: AssetsLinuxIcon('icon.png'), + ); final ByteDataLinuxIcon icon = ByteDataLinuxIcon( - LinuxRawIconData( - data: Uint8List(64), - width: 8, - height: 8, - ), + LinuxRawIconData(data: Uint8List(64), width: 8, height: 8), ); final LinuxNotificationDetails details = LinuxNotificationDetails( icon: icon, @@ -350,27 +316,21 @@ void main() { final List values = buildNotifyMethodValues( hints: { - 'image-data': DBusStruct( - [ - DBusInt32(icon.iconData.width), - DBusInt32(icon.iconData.height), - DBusInt32(icon.iconData.rowStride), - DBusBoolean(icon.iconData.hasAlpha), - DBusInt32(icon.iconData.bitsPerSample), - DBusInt32(icon.iconData.channels), - DBusArray.byte(icon.iconData.data), - ], - ), + 'image-data': DBusStruct([ + DBusInt32(icon.iconData.width), + DBusInt32(icon.iconData.height), + DBusInt32(icon.iconData.rowStride), + DBusBoolean(icon.iconData.hasAlpha), + DBusInt32(icon.iconData.bitsPerSample), + DBusInt32(icon.iconData.channels), + DBusArray.byte(icon.iconData.data), + ]), }, ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -381,9 +341,9 @@ void main() { test('Theme details icon', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultIcon: AssetsLinuxIcon('icon.png'), - ); + defaultActionName: kDefaultActionName, + defaultIcon: AssetsLinuxIcon('icon.png'), + ); final LinuxNotificationDetails details = LinuxNotificationDetails( icon: ThemeLinuxIcon('test'), @@ -399,12 +359,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -415,9 +371,9 @@ void main() { test('Default icon', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultIcon: AssetsLinuxIcon('icon.png'), - ); + defaultActionName: kDefaultActionName, + defaultIcon: AssetsLinuxIcon('icon.png'), + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -429,12 +385,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null); @@ -460,12 +412,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -476,9 +424,9 @@ void main() { test('Assets sound in details', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultSound: AssetsLinuxSound('default_sound.mp3'), - ); + defaultActionName: kDefaultActionName, + defaultSound: AssetsLinuxSound('default_sound.mp3'), + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -501,12 +449,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -517,9 +461,9 @@ void main() { test('Theme sound in details', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultSound: AssetsLinuxSound('default_sound.mp3'), - ); + defaultActionName: kDefaultActionName, + defaultSound: AssetsLinuxSound('default_sound.mp3'), + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -537,12 +481,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -553,9 +493,9 @@ void main() { test('Default sound', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultSound: AssetsLinuxSound('sound.mp3'), - ); + defaultActionName: kDefaultActionName, + defaultSound: AssetsLinuxSound('sound.mp3'), + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -574,12 +514,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null); @@ -607,12 +543,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -640,12 +572,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -667,18 +595,12 @@ void main() { ); final List values = buildNotifyMethodValues( - hints: { - 'resident': DBusBoolean(details.resident), - }, + hints: {'resident': DBusBoolean(details.resident)}, ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -706,12 +628,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -722,9 +640,9 @@ void main() { test('Default suppress sound', () async { const LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultSuppressSound: true, - ); + defaultActionName: kDefaultActionName, + defaultSuppressSound: true, + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -738,12 +656,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null); @@ -771,12 +685,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -805,12 +715,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -831,21 +737,13 @@ void main() { customHints: [ LinuxNotificationCustomHint( 'array-hint', - LinuxHintArrayValue( - [ - LinuxHintStringValue('1'), - LinuxHintStringValue('2'), - ], - ), - ), - LinuxNotificationCustomHint( - 'bool-hint', - LinuxHintBoolValue(true), - ), - LinuxNotificationCustomHint( - 'byte-hint', - LinuxHintByteValue(1), + LinuxHintArrayValue([ + LinuxHintStringValue('1'), + LinuxHintStringValue('2'), + ]), ), + LinuxNotificationCustomHint('bool-hint', LinuxHintBoolValue(true)), + LinuxNotificationCustomHint('byte-hint', LinuxHintByteValue(1)), LinuxNotificationCustomHint( 'dict-hint', LinuxHintDictValue( @@ -859,43 +757,23 @@ void main() { 'double-hint', LinuxHintDoubleValue(1.1), ), - LinuxNotificationCustomHint( - 'int16-hint', - LinuxHintInt16Value(1), - ), - LinuxNotificationCustomHint( - 'int32-hint', - LinuxHintInt32Value(1), - ), - LinuxNotificationCustomHint( - 'int64-hint', - LinuxHintInt64Value(1), - ), + LinuxNotificationCustomHint('int16-hint', LinuxHintInt16Value(1)), + LinuxNotificationCustomHint('int32-hint', LinuxHintInt32Value(1)), + LinuxNotificationCustomHint('int64-hint', LinuxHintInt64Value(1)), LinuxNotificationCustomHint( 'string-hint', LinuxHintStringValue('test'), ), LinuxNotificationCustomHint( 'struct-hint', - LinuxHintStructValue( - [ - LinuxHintStringValue('test'), - LinuxHintBoolValue(true), - ], - ), - ), - LinuxNotificationCustomHint( - 'uint16-hint', - LinuxHintUint16Value(1), - ), - LinuxNotificationCustomHint( - 'uint32-hint', - LinuxHintUint32Value(1), - ), - LinuxNotificationCustomHint( - 'uint64-hint', - LinuxHintUint64Value(1), + LinuxHintStructValue([ + LinuxHintStringValue('test'), + LinuxHintBoolValue(true), + ]), ), + LinuxNotificationCustomHint('uint16-hint', LinuxHintUint16Value(1)), + LinuxNotificationCustomHint('uint32-hint', LinuxHintUint32Value(1)), + LinuxNotificationCustomHint('uint64-hint', LinuxHintUint64Value(1)), LinuxNotificationCustomHint( 'variant-hint', LinuxHintVariantValue(LinuxHintByteValue(1)), @@ -905,13 +783,10 @@ void main() { final List values = buildNotifyMethodValues( hints: { - 'array-hint': DBusArray( - DBusSignature('s'), - [ - const DBusString('1'), - const DBusString('2'), - ], - ), + 'array-hint': DBusArray(DBusSignature('s'), [ + const DBusString('1'), + const DBusString('2'), + ]), 'bool-hint': const DBusBoolean(true), 'byte-hint': const DBusByte(1), 'dict-hint': DBusDict( @@ -927,12 +802,10 @@ void main() { 'int32-hint': const DBusInt32(1), 'int64-hint': const DBusInt64(1), 'string-hint': const DBusString('test'), - 'struct-hint': DBusStruct( - [ - const DBusString('test'), - const DBusBoolean(true), - ], - ), + 'struct-hint': DBusStruct([ + const DBusString('test'), + const DBusBoolean(true), + ]), 'uint16-hint': const DBusUint16(1), 'uint32-hint': const DBusUint32(1), 'uint64-hint': const DBusUint64(1), @@ -941,12 +814,8 @@ void main() { ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -957,9 +826,9 @@ void main() { test('File path details icon', () async { final LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultIcon: FilePathLinuxIcon('/foo/bar/icon.png'), - ); + defaultActionName: kDefaultActionName, + defaultIcon: FilePathLinuxIcon('/foo/bar/icon.png'), + ); final LinuxNotificationDetails details = LinuxNotificationDetails( icon: FilePathLinuxIcon('/foo/bar/icon.png'), @@ -970,16 +839,13 @@ void main() { systemId: 1, ); - final List values = - buildNotifyMethodValues(appIcon: '/foo/bar/icon.png'); + final List values = buildNotifyMethodValues( + appIcon: '/foo/bar/icon.png', + ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -1002,33 +868,18 @@ void main() { const LinuxNotificationDetails details = LinuxNotificationDetails( actions: [ - LinuxNotificationAction( - key: '1', - label: 'action1', - ), - LinuxNotificationAction( - key: '2', - label: 'action2', - ), + LinuxNotificationAction(key: '1', label: 'action1'), + LinuxNotificationAction(key: '2', label: 'action2'), ], ); final List values = buildNotifyMethodValues( - actions: [ - '1', - 'action1', - '2', - 'action2', - ], + actions: ['1', 'action1', '2', 'action2'], ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -1050,31 +901,19 @@ void main() { const LinuxNotificationDetails details = LinuxNotificationDetails( actions: [ - LinuxNotificationAction( - key: 'media-eject', - label: 'eject', - ), + LinuxNotificationAction(key: 'media-eject', label: 'eject'), ], actionKeyAsIconName: true, ); final List values = buildNotifyMethodValues( - actions: [ - 'media-eject', - 'eject', - ], - hints: { - 'action-icons': const DBusBoolean(true), - }, + actions: ['media-eject', 'eject'], + hints: {'action-icons': const DBusBoolean(true)}, ); mockNotifyMethod(notify.systemId); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => null); - when( - mockStorage.insert(notify), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => null); + when(mockStorage.insert(notify)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.show(notify.id, null, null, details: details); @@ -1086,9 +925,9 @@ void main() { test('Cancel', () async { const LinuxInitializationSettings initSettings = LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - defaultSuppressSound: true, - ); + defaultActionName: kDefaultActionName, + defaultSuppressSound: true, + ); const LinuxNotificationInfo notify = LinuxNotificationInfo( id: 0, @@ -1097,44 +936,28 @@ void main() { mockCloseMethod(); - when( - mockStorage.getById(notify.id), - ).thenAnswer((_) async => notify); - when( - mockStorage.removeById(notify.id), - ).thenAnswer((_) async => true); + when(mockStorage.getById(notify.id)).thenAnswer((_) async => notify); + when(mockStorage.removeById(notify.id)).thenAnswer((_) async => true); await manager.initialize(initSettings); await manager.cancel(notify.id); verifyCloseMethod(notify.systemId).called(1); - verify( - mockStorage.removeById(notify.id), - ).called(1); + verify(mockStorage.removeById(notify.id)).called(1); }); test('Cancel all', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - ); + LinuxInitializationSettings(defaultActionName: kDefaultActionName); const List notifications = [ - LinuxNotificationInfo( - id: 0, - systemId: 1, - ), - LinuxNotificationInfo( - id: 1, - systemId: 2, - ), + LinuxNotificationInfo(id: 0, systemId: 1), + LinuxNotificationInfo(id: 1, systemId: 2), ]; mockCloseMethod(); - when( - mockStorage.getAll(), - ).thenAnswer((_) async => notifications); + when(mockStorage.getAll()).thenAnswer((_) async => notifications); when( mockStorage.removeByIdList( notifications.map((LinuxNotificationInfo n) => n.id).toList(), @@ -1156,19 +979,11 @@ void main() { test('Notification closed by system', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - ); + LinuxInitializationSettings(defaultActionName: kDefaultActionName); const List notifications = [ - LinuxNotificationInfo( - id: 0, - systemId: 1, - ), - LinuxNotificationInfo( - id: 1, - systemId: 2, - ), + LinuxNotificationInfo(id: 0, systemId: 1), + LinuxNotificationInfo(id: 1, systemId: 2), ]; final List> completers = >[]; @@ -1178,9 +993,9 @@ void main() { ).thenAnswer((_) async => true); } - when( - mockNotifyClosedSignal.listen(any), - ).thenAnswer((Invocation invocation) { + when(mockNotifyClosedSignal.listen(any)).thenAnswer(( + Invocation invocation, + ) { final Future Function(DBusSignal) callback = invocation.positionalArguments.single; for (final LinuxNotificationInfo notify in notifications) { @@ -1213,29 +1028,17 @@ void main() { ); for (final LinuxNotificationInfo notify in notifications) { - verify( - mockStorage.removeBySystemId(notify.systemId), - ).called(1); + verify(mockStorage.removeBySystemId(notify.systemId)).called(1); } }); test('Open notification', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - ); + LinuxInitializationSettings(defaultActionName: kDefaultActionName); const List notifications = [ - LinuxNotificationInfo( - id: 0, - systemId: 1, - payload: 'payload1', - ), - LinuxNotificationInfo( - id: 1, - systemId: 2, - payload: 'payload2', - ), + LinuxNotificationInfo(id: 0, systemId: 1, payload: 'payload1'), + LinuxNotificationInfo(id: 1, systemId: 2, payload: 'payload2'), ]; final List> completers = >[]; @@ -1245,9 +1048,9 @@ void main() { ).thenAnswer((_) async => notify); completers.add(Completer()); } - when( - mockActionInvokedSignal.listen(any), - ).thenAnswer((Invocation invocation) { + when(mockActionInvokedSignal.listen(any)).thenAnswer(( + Invocation invocation, + ) { final Future Function(DBusSignal) callback = invocation.positionalArguments.single; for (final LinuxNotificationInfo notify in notifications) { @@ -1284,9 +1087,7 @@ void main() { ); for (final LinuxNotificationInfo notify in notifications) { - verify( - mockStorage.getBySystemId(notify.systemId), - ).called(1); + verify(mockStorage.getBySystemId(notify.systemId)).called(1); } }); @@ -1302,26 +1103,21 @@ void main() { replySignature: DBusSignature('as'), ), ).thenAnswer( - (_) async => DBusMethodSuccessResponse( - [ - DBusArray( - DBusSignature('s'), - [ - const DBusString('body'), - const DBusString('body-hyperlinks'), - const DBusString('body-images'), - const DBusString('body-markup'), - const DBusString('icon-multi'), - const DBusString('icon-static'), - const DBusString('persistence'), - const DBusString('sound'), - const DBusString('test-cap'), - const DBusString('actions'), - const DBusString('action-icons'), - ], - ), - ], - ), + (_) async => DBusMethodSuccessResponse([ + DBusArray(DBusSignature('s'), [ + const DBusString('body'), + const DBusString('body-hyperlinks'), + const DBusString('body-images'), + const DBusString('body-markup'), + const DBusString('icon-multi'), + const DBusString('icon-static'), + const DBusString('persistence'), + const DBusString('sound'), + const DBusString('test-cap'), + const DBusString('actions'), + const DBusString('action-icons'), + ]), + ]), ); await manager.initialize(initSettings); @@ -1345,34 +1141,22 @@ void main() { test('Get system ID map', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - ); + LinuxInitializationSettings(defaultActionName: kDefaultActionName); const List notifications = [ - LinuxNotificationInfo( - id: 0, - systemId: 1, - ), - LinuxNotificationInfo( - id: 1, - systemId: 2, - ), + LinuxNotificationInfo(id: 0, systemId: 1), + LinuxNotificationInfo(id: 1, systemId: 2), ]; - when( - mockStorage.getAll(), - ).thenAnswer((_) async => notifications); + when(mockStorage.getAll()).thenAnswer((_) async => notifications); await manager.initialize(initSettings); expect( await manager.getSystemIdMap(), Map.fromEntries( notifications.map( - (LinuxNotificationInfo notify) => MapEntry( - notify.id, - notify.systemId, - ), + (LinuxNotificationInfo notify) => + MapEntry(notify.id, notify.systemId), ), ), ); @@ -1380,9 +1164,7 @@ void main() { test('Open notification action', () async { const LinuxInitializationSettings initSettings = - LinuxInitializationSettings( - defaultActionName: kDefaultActionName, - ); + LinuxInitializationSettings(defaultActionName: kDefaultActionName); const List notifications = [ LinuxNotificationInfo( @@ -1408,9 +1190,9 @@ void main() { ).thenAnswer((_) async => notify); completers.add(Completer()); } - when( - mockActionInvokedSignal.listen(any), - ).thenAnswer((Invocation invocation) { + when(mockActionInvokedSignal.listen(any)).thenAnswer(( + Invocation invocation, + ) { final Future Function(DBusSignal) callback = invocation.positionalArguments.single; for (final LinuxNotificationInfo notify in notifications) { @@ -1447,9 +1229,7 @@ void main() { ); for (final LinuxNotificationInfo notify in notifications) { - verify( - mockStorage.getBySystemId(notify.systemId), - ).called(1); + verify(mockStorage.getBySystemId(notify.systemId)).called(1); } }); }); diff --git a/flutter_local_notifications_linux/test/storage_test.dart b/flutter_local_notifications_linux/test/storage_test.dart index 61ead7273..a985581be 100644 --- a/flutter_local_notifications_linux/test/storage_test.dart +++ b/flutter_local_notifications_linux/test/storage_test.dart @@ -40,27 +40,18 @@ void main() { mockFs = MockFileSystem(); mockStorageFile = MockFile(); - when( - mockPlatformInfo.getAll(), - ).thenAnswer((_) async => platformInfo); + when(mockPlatformInfo.getAll()).thenAnswer((_) async => platformInfo); when(mockFs.open(fileStoragePath)).thenReturn(mockStorageFile); }); setUp(() { - storage = NotificationStorage( - platformInfo: mockPlatformInfo, - fs: mockFs, - ); + storage = NotificationStorage(platformInfo: mockPlatformInfo, fs: mockFs); }); test('Insert', () async { const List notifications = [ LinuxNotificationInfo(id: 1, systemId: 1), - LinuxNotificationInfo( - id: 2, - systemId: 2, - payload: 'test', - ), + LinuxNotificationInfo(id: 2, systemId: 2, payload: 'test'), LinuxNotificationInfo( id: 3, systemId: 3, @@ -73,21 +64,15 @@ void main() { ]; when(mockStorageFile.existsSync()).thenReturn(false); - when( - mockStorageFile.createSync(recursive: true), - ).thenAnswer((_) {}); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.createSync(recursive: true)).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); expect(await storage.insert(notifications[0]), isTrue); expect(await storage.insert(notifications[1]), isTrue); expect(await storage.insert(notifications[2]), isTrue); - verify( - mockStorageFile.createSync(recursive: true), - ).called(3); + verify(mockStorageFile.createSync(recursive: true)).called(3); verify( mockStorageFile.writeAsStringSync( jsonEncode([notifications[0]]), @@ -101,17 +86,11 @@ void main() { test('Remove', () async { const List notifications = [ LinuxNotificationInfo(id: 1, systemId: 1), - LinuxNotificationInfo( - id: 2, - systemId: 2, - payload: 'test', - ), + LinuxNotificationInfo(id: 2, systemId: 2, payload: 'test'), ]; when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); await storage.insert(notifications[0]); @@ -135,25 +114,20 @@ void main() { test('Get all', () async { const List notifications = [ LinuxNotificationInfo(id: 1, systemId: 1), + LinuxNotificationInfo(id: 2, systemId: 2, payload: 'test'), LinuxNotificationInfo( - id: 2, - systemId: 2, + id: 3, + systemId: 3, payload: 'test', + actions: [ + LinuxNotificationActionInfo(key: '1'), + LinuxNotificationActionInfo(key: '2'), + ], ), - LinuxNotificationInfo( - id: 3, - systemId: 3, - payload: 'test', - actions: [ - LinuxNotificationActionInfo(key: '1'), - LinuxNotificationActionInfo(key: '2'), - ]), ]; when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); expect(await storage.getAll(), []); @@ -170,10 +144,7 @@ void main() { await storage.insert(notifications[1]); await storage.insert(notifications[2]); - expect( - await storage.getAll(), - notifications, - ); + expect(await storage.getAll(), notifications); }); test('Get by ID', () async { @@ -183,9 +154,7 @@ void main() { ); when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); expect(await storage.getAll(), []); @@ -211,9 +180,7 @@ void main() { ); when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when( mockStorageFile.readAsStringSync(), @@ -231,17 +198,11 @@ void main() { test('Remove by ID list', () async { const List notifications = [ LinuxNotificationInfo(id: 1, systemId: 1), - LinuxNotificationInfo( - id: 2, - systemId: 2, - payload: 'test', - ), + LinuxNotificationInfo(id: 2, systemId: 2, payload: 'test'), ]; when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); await storage.insert(notifications[0]); @@ -269,9 +230,7 @@ void main() { ); when(mockStorageFile.existsSync()).thenReturn(true); - when( - mockStorageFile.writeAsStringSync(any), - ).thenAnswer((_) {}); + when(mockStorageFile.writeAsStringSync(any)).thenAnswer((_) {}); when(mockStorageFile.readAsStringSync()).thenReturn(''); await storage.insert(notification); diff --git a/flutter_local_notifications_platform_interface/lib/flutter_local_notifications_platform_interface.dart b/flutter_local_notifications_platform_interface/lib/flutter_local_notifications_platform_interface.dart index f5ee169bb..48d1c319a 100644 --- a/flutter_local_notifications_platform_interface/lib/flutter_local_notifications_platform_interface.dart +++ b/flutter_local_notifications_platform_interface/lib/flutter_local_notifications_platform_interface.dart @@ -29,15 +29,20 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface { /// Returns info on if a notification had been used to launch the application. Future - getNotificationAppLaunchDetails() async { + getNotificationAppLaunchDetails() async { throw UnimplementedError( - 'getNotificationAppLaunchDetails() has not been implemented'); + 'getNotificationAppLaunchDetails() has not been implemented', + ); } /// Show a notification with an optional payload that will be passed back to /// the app when a notification is tapped on. - Future show(int id, String? title, String? body, - {String? payload}) async { + Future show( + int id, + String? title, + String? body, { + String? payload, + }) async { throw UnimplementedError('show() has not been implemented'); } @@ -47,7 +52,11 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface { /// notification will be an hour after the method has been called and then /// every hour after that. Future periodicallyShow( - int id, String? title, String? body, RepeatInterval repeatInterval) { + int id, + String? title, + String? body, + RepeatInterval repeatInterval, + ) { throw UnimplementedError('periodicallyShow() has not been implemented'); } @@ -60,9 +69,14 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface { /// /// [repeatDurationInterval] must be at least one minute. Future periodicallyShowWithDuration( - int id, String? title, String? body, Duration repeatDurationInterval) { + int id, + String? title, + String? body, + Duration repeatDurationInterval, + ) { throw UnimplementedError( - 'periodicallyShowWithDuration() has not been implemented'); + 'periodicallyShowWithDuration() has not been implemented', + ); } /// Cancels/removes the notification with the specified id. @@ -83,13 +97,15 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface { /// This only applies to notifications that have been scheduled. Future cancelAllPendingNotifications() async { throw UnimplementedError( - 'cancelAllPendingNotifications() has not been implemented'); + 'cancelAllPendingNotifications() has not been implemented', + ); } /// Returns a list of notifications pending to be delivered/shown Future> pendingNotificationRequests() { throw UnimplementedError( - 'pendingNotificationRequest() has not been implemented'); + 'pendingNotificationRequest() has not been implemented', + ); } /// Returns the list of active notifications shown by the application that @@ -101,6 +117,7 @@ abstract class FlutterLocalNotificationsPlatform extends PlatformInterface { /// support the method at all, it will throw an [UnimplementedError]. Future> getActiveNotifications() { throw UnimplementedError( - 'getActiveNotifications() has not been implemented'); + 'getActiveNotifications() has not been implemented', + ); } } diff --git a/flutter_local_notifications_platform_interface/lib/src/helpers.dart b/flutter_local_notifications_platform_interface/lib/src/helpers.dart index 7c17a7946..ceed7fdfe 100644 --- a/flutter_local_notifications_platform_interface/lib/src/helpers.dart +++ b/flutter_local_notifications_platform_interface/lib/src/helpers.dart @@ -4,8 +4,11 @@ void validateId(int id) { ArgumentError.checkNotNull(id, 'id'); if (id > 0x7FFFFFFF || id < -0x80000000) { - throw ArgumentError.value(id, 'id', - 'must fit within the size of a 32-bit integer i.e. in the range [-2^31, 2^31 - 1]'); // ignore: lines_longer_than_80_chars + throw ArgumentError.value( + id, + 'id', + 'must fit within the size of a 32-bit integer i.e. in the range [-2^31, 2^31 - 1]', + ); // ignore: lines_longer_than_80_chars } } @@ -16,7 +19,10 @@ void validateId(int id) { void validateRepeatDurationInterval(Duration repeatDurationInterval) { ArgumentError.checkNotNull(repeatDurationInterval, 'repeatDurationInterval'); if (repeatDurationInterval.inMinutes < 1) { - throw ArgumentError.value(repeatDurationInterval, 'repeatDurationInterval', - 'must be at one minute or more'); + throw ArgumentError.value( + repeatDurationInterval, + 'repeatDurationInterval', + 'must be at one minute or more', + ); } } diff --git a/flutter_local_notifications_platform_interface/lib/src/typedefs.dart b/flutter_local_notifications_platform_interface/lib/src/typedefs.dart index 473947ad4..8694fa0c3 100644 --- a/flutter_local_notifications_platform_interface/lib/src/typedefs.dart +++ b/flutter_local_notifications_platform_interface/lib/src/typedefs.dart @@ -2,10 +2,10 @@ import 'types.dart'; /// Signature of callback triggered on main isolate when a user taps on a /// notification or a notification action. -typedef DidReceiveNotificationResponseCallback = void Function( - NotificationResponse details); +typedef DidReceiveNotificationResponseCallback = + void Function(NotificationResponse details); /// Signature of callback triggered on background isolate when a user taps on a /// notification or a notification action. -typedef DidReceiveBackgroundNotificationResponseCallback = void Function( - NotificationResponse details); +typedef DidReceiveBackgroundNotificationResponseCallback = + void Function(NotificationResponse details); diff --git a/flutter_local_notifications_platform_interface/lib/src/types.dart b/flutter_local_notifications_platform_interface/lib/src/types.dart index caf627540..7747b922a 100644 --- a/flutter_local_notifications_platform_interface/lib/src/types.dart +++ b/flutter_local_notifications_platform_interface/lib/src/types.dart @@ -10,14 +10,18 @@ enum RepeatInterval { daily, /// Weekly interval. - weekly + weekly, } /// Details of a pending notification that has not been delivered. class PendingNotificationRequest { /// Constructs an instance of [PendingNotificationRequest]. const PendingNotificationRequest( - this.id, this.title, this.body, this.payload); + this.id, + this.title, + this.body, + this.payload, + ); /// The notification's id. final int id; diff --git a/flutter_local_notifications_windows/lib/src/details/notification_audio.dart b/flutter_local_notifications_windows/lib/src/details/notification_audio.dart index 4c5ff8474..aa246f697 100644 --- a/flutter_local_notifications_windows/lib/src/details/notification_audio.dart +++ b/flutter_local_notifications_windows/lib/src/details/notification_audio.dart @@ -87,16 +87,16 @@ enum WindowsNotificationSound { class WindowsNotificationAudio { /// No sound will play during this notification. WindowsNotificationAudio.silent() - : source = WindowsNotificationSound.defaultSound.name, - shouldLoop = false, - isSilent = true; + : source = WindowsNotificationSound.defaultSound.name, + shouldLoop = false, + isSilent = true; /// Audio from a Windows preset. See [WindowsNotificationSound] for options. WindowsNotificationAudio.preset({ required WindowsNotificationSound sound, this.shouldLoop = false, - }) : isSilent = false, - source = sound.name; + }) : isSilent = false, + source = sound.name; /// Uses an audio file from a Flutter asset. /// @@ -110,10 +110,10 @@ class WindowsNotificationAudio { String assetName, { this.shouldLoop = false, WindowsNotificationSound fallback = WindowsNotificationSound.defaultSound, - }) : isSilent = false, - source = MsixUtils.hasPackageIdentity() - ? MsixUtils.getAssetUri(assetName).toString() - : fallback.name; + }) : isSilent = false, + source = MsixUtils.hasPackageIdentity() + ? MsixUtils.getAssetUri(assetName).toString() + : fallback.name; /// Whether this audio should loop. final bool shouldLoop; diff --git a/flutter_local_notifications_windows/lib/src/details/notification_input.dart b/flutter_local_notifications_windows/lib/src/details/notification_input.dart index f13291efb..e6ce74c89 100644 --- a/flutter_local_notifications_windows/lib/src/details/notification_input.dart +++ b/flutter_local_notifications_windows/lib/src/details/notification_input.dart @@ -10,11 +10,7 @@ enum WindowsInputType { /// A text or multiple choice input element in a Windows notification. sealed class WindowsInput { /// Creates an input field in a notification. - const WindowsInput({ - required this.id, - required this.type, - this.title, - }); + const WindowsInput({required this.id, required this.type, this.title}); /// A unique ID for this input. /// @@ -61,10 +57,7 @@ class WindowsSelectionInput extends WindowsInput { /// An option that can be selected by a [WindowsSelectionInput]. class WindowsSelection { /// Creates a selectable choice. - const WindowsSelection({ - required this.id, - required this.content, - }); + const WindowsSelection({required this.id, required this.content}); /// A unique ID for this item. final String id; diff --git a/flutter_local_notifications_windows/lib/src/details/notification_to_xml.dart b/flutter_local_notifications_windows/lib/src/details/notification_to_xml.dart index 67184c1b1..24f87edbe 100644 --- a/flutter_local_notifications_windows/lib/src/details/notification_to_xml.dart +++ b/flutter_local_notifications_windows/lib/src/details/notification_to_xml.dart @@ -41,7 +41,8 @@ String notificationToXml({ details?.buildXml(builder); }, ); - return builder - .buildDocument() - .toXmlString(pretty: true, indentAttribute: (_) => true); + return builder.buildDocument().toXmlString( + pretty: true, + indentAttribute: (_) => true, + ); } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/audio.dart b/flutter_local_notifications_windows/lib/src/details/xml/audio.dart index 586a53f0d..d62539fc9 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/audio.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/audio.dart @@ -7,11 +7,11 @@ extension AudioToXml on WindowsNotificationAudio { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio void buildXml(XmlBuilder builder) => builder.element( - 'audio', - attributes: { - 'src': source, - 'silent': isSilent.toString(), - 'loop': shouldLoop.toString(), - }, - ); + 'audio', + attributes: { + 'src': source, + 'silent': isSilent.toString(), + 'loop': shouldLoop.toString(), + }, + ); } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/details.dart b/flutter_local_notifications_windows/lib/src/details/xml/details.dart index 98ba8d6a7..c91e5abef 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/details.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/details.dart @@ -20,8 +20,11 @@ extension on DateTime { final Duration offset = timeZoneOffset; final String sign = offset.isNegative ? '-' : '+'; final String hours = offset.inHours.abs().toString().padLeft(2, '0'); - final String minutes = - offset.inMinutes.abs().remainder(60).toString().padLeft(2, '0'); + final String minutes = offset.inMinutes + .abs() + .remainder(60) + .toString() + .padLeft(2, '0'); final String offsetString = '$sign$hours:$minutes'; // Get first part of properly formatted ISO 8601 date final String formattedDate = toIso8601String().split('.').first; @@ -83,9 +86,8 @@ extension DetailsToXml on WindowsNotificationDetails { /// XML attributes for the toast notification as a whole. Map get attributes => { - if (duration != null) 'duration': duration!.name, - if (timestamp != null) - 'displayTimestamp': timestamp!.toIso8601StringTz(), - if (scenario != null) 'scenario': scenario!.name, - }; + if (duration != null) 'duration': duration!.name, + if (timestamp != null) 'displayTimestamp': timestamp!.toIso8601StringTz(), + if (scenario != null) 'scenario': scenario!.name, + }; } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/header.dart b/flutter_local_notifications_windows/lib/src/details/xml/header.dart index b7de790d4..12a8a66ea 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/header.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/header.dart @@ -8,12 +8,12 @@ extension HeaderToXml on WindowsHeader { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-header void buildXml(XmlBuilder builder) => builder.element( - 'header', - attributes: { - 'id': id, - 'title': title, - 'arguments': arguments, - if (activation != null) 'activationType': activation!.name, - }, - ); + 'header', + attributes: { + 'id': id, + 'title': title, + 'arguments': arguments, + if (activation != null) 'activationType': activation!.name, + }, + ); } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/input.dart b/flutter_local_notifications_windows/lib/src/details/xml/input.dart index 407421a5a..2d1f8aed3 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/input.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/input.dart @@ -8,15 +8,14 @@ extension TextInputToXml on WindowsTextInput { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-input void buildXml(XmlBuilder builder) => builder.element( - 'input', - attributes: { - 'id': id, - 'type': type.name, - if (title != null) 'title': title!, - if (placeHolderContent != null) - 'placeHolderContent': placeHolderContent!, - }, - ); + 'input', + attributes: { + 'id': id, + 'type': type.name, + if (title != null) 'title': title!, + if (placeHolderContent != null) 'placeHolderContent': placeHolderContent!, + }, + ); } /// Converts a [WindowsSelectionInput] to XML @@ -25,19 +24,19 @@ extension SelectionInputToXml on WindowsSelectionInput { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-input void buildXml(XmlBuilder builder) => builder.element( - 'input', - attributes: { - 'id': id, - 'type': type.name, - if (title != null) 'title': title!, - if (defaultItem != null) 'defaultInput': defaultItem!, - }, - nest: () { - for (final WindowsSelection item in items) { - item.buildXml(builder); - } - }, - ); + 'input', + attributes: { + 'id': id, + 'type': type.name, + if (title != null) 'title': title!, + if (defaultItem != null) 'defaultInput': defaultItem!, + }, + nest: () { + for (final WindowsSelection item in items) { + item.buildXml(builder); + } + }, + ); } /// Converts a [WindowsSelection] to XML @@ -46,10 +45,7 @@ extension SelectionToXml on WindowsSelection { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-selection void buildXml(XmlBuilder builder) => builder.element( - 'selection', - attributes: { - 'id': id, - 'content': content, - }, - ); + 'selection', + attributes: {'id': id, 'content': content}, + ); } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/progress.dart b/flutter_local_notifications_windows/lib/src/details/xml/progress.dart index ee8ef441b..765d04efb 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/progress.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/progress.dart @@ -8,14 +8,14 @@ extension ProgressBarToXml on WindowsProgressBar { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-progress void buildXml(XmlBuilder builder) => builder.element( - 'progress', - attributes: { - 'status': status, - 'value': '{$id-progressValue}', - if (title != null) 'title': title!, - if (label != null) 'valueStringOverride': '{$id-progressString}', - }, - ); + 'progress', + attributes: { + 'status': status, + 'value': '{$id-progressValue}', + if (title != null) 'title': title!, + if (label != null) 'valueStringOverride': '{$id-progressString}', + }, + ); /// The data bindings for this progress bar. /// @@ -24,7 +24,7 @@ extension ProgressBarToXml on WindowsProgressBar { /// dynamically later by calling /// [FlutterLocalNotificationsWindows.updateProgressBar]. Map get data => { - '$id-progressValue': value?.toString() ?? 'indeterminate', - if (label != null) '$id-progressString': label!, - }; + '$id-progressValue': value?.toString() ?? 'indeterminate', + if (label != null) '$id-progressString': label!, + }; } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/row.dart b/flutter_local_notifications_windows/lib/src/details/xml/row.dart index cada3be4a..d60fe288d 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/row.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/row.dart @@ -12,24 +12,24 @@ extension RowToXml on WindowsRow { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-group void buildXml(XmlBuilder builder) => builder.element( - 'group', - nest: () { - for (final WindowsColumn column in columns) { - builder.element( - 'subgroup', - attributes: {'hint-weight': '1'}, - nest: () { - for (final WindowsNotificationPart part in column.parts) { - switch (part) { - case WindowsImage(): - part.buildXml(builder); - case WindowsNotificationText(): - part.buildXml(builder); - } - } - }, - ); - } - }, - ); + 'group', + nest: () { + for (final WindowsColumn column in columns) { + builder.element( + 'subgroup', + attributes: {'hint-weight': '1'}, + nest: () { + for (final WindowsNotificationPart part in column.parts) { + switch (part) { + case WindowsImage(): + part.buildXml(builder); + case WindowsNotificationText(): + part.buildXml(builder); + } + } + }, + ); + } + }, + ); } diff --git a/flutter_local_notifications_windows/lib/src/details/xml/text.dart b/flutter_local_notifications_windows/lib/src/details/xml/text.dart index 419e66422..eed381971 100644 --- a/flutter_local_notifications_windows/lib/src/details/xml/text.dart +++ b/flutter_local_notifications_windows/lib/src/details/xml/text.dart @@ -8,14 +8,14 @@ extension TextToXml on WindowsNotificationText { /// /// See: https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-text void buildXml(XmlBuilder builder) => builder.element( - 'text', - attributes: { - if (languageCode != null) 'lang': languageCode!, - if (placement != null) 'placement': placement!.name, - 'hint-callScenarioCenterAlign': centerIfCall.toString(), - 'hint-align': 'center', - if (isCaption) 'hint-style': 'captionsubtle', - }, - nest: text, - ); + 'text', + attributes: { + if (languageCode != null) 'lang': languageCode!, + if (placement != null) 'placement': placement!.name, + 'hint-callScenarioCenterAlign': centerIfCall.toString(), + 'hint-align': 'center', + if (isCaption) 'hint-style': 'captionsubtle', + }, + nest: text, + ); } diff --git a/flutter_local_notifications_windows/lib/src/ffi/bindings.dart b/flutter_local_notifications_windows/lib/src/ffi/bindings.dart index 475670480..aebabbfc6 100644 --- a/flutter_local_notifications_windows/lib/src/ffi/bindings.dart +++ b/flutter_local_notifications_windows/lib/src/ffi/bindings.dart @@ -16,17 +16,16 @@ import 'package:ffi/ffi.dart' as pkg_ffi; class NotificationsPluginBindings { /// Holds the symbol lookup function. final ffi.Pointer Function(String symbolName) - _lookup; + _lookup; /// The symbols are looked up in [dynamicLibrary]. NotificationsPluginBindings(ffi.DynamicLibrary dynamicLibrary) - : _lookup = dynamicLibrary.lookup; + : _lookup = dynamicLibrary.lookup; /// The symbols are looked up with [lookup]. NotificationsPluginBindings.fromLookup( - ffi.Pointer Function(String symbolName) - lookup) - : _lookup = lookup; + ffi.Pointer Function(String symbolName) lookup, + ) : _lookup = lookup; /// Checks whether the current application has package identity. /// @@ -39,22 +38,19 @@ class NotificationsPluginBindings { late final _hasPackageIdentityPtr = _lookup>('hasPackageIdentity'); - late final _hasPackageIdentity = - _hasPackageIdentityPtr.asFunction(); + late final _hasPackageIdentity = _hasPackageIdentityPtr + .asFunction(); - bool isValidXml( - ffi.Pointer xml, - ) { - return _isValidXml( - xml, - ); + bool isValidXml(ffi.Pointer xml) { + return _isValidXml(xml); } late final _isValidXmlPtr = _lookup)>>( - 'isValidXml'); - late final _isValidXml = - _isValidXmlPtr.asFunction)>(); + 'isValidXml', + ); + late final _isValidXml = _isValidXmlPtr + .asFunction)>(); /// Allocates a new plugin that must be released with [disposePlugin]. ffi.Pointer createPlugin() { @@ -63,24 +59,22 @@ class NotificationsPluginBindings { late final _createPluginPtr = _lookup Function()>>( - 'createPlugin'); - late final _createPlugin = - _createPluginPtr.asFunction Function()>(); + 'createPlugin', + ); + late final _createPlugin = _createPluginPtr + .asFunction Function()>(); /// Releases the plugin and any resources it was holding onto. - void disposePlugin( - ffi.Pointer ptr, - ) { - return _disposePlugin( - ptr, - ); + void disposePlugin(ffi.Pointer ptr) { + return _disposePlugin(ptr); } late final _disposePluginPtr = _lookup)>>( - 'disposePlugin'); - late final _disposePlugin = - _disposePluginPtr.asFunction)>(); + 'disposePlugin', + ); + late final _disposePlugin = _disposePluginPtr + .asFunction)>(); /// Initializes the plugin and registers the callback to be run when a notification is pressed. bool init( @@ -91,33 +85,33 @@ class NotificationsPluginBindings { ffi.Pointer iconPath, NativeNotificationCallback callback, ) { - return _init( - plugin, - appName, - aumId, - guid, - iconPath, - callback, - ); + return _init(plugin, appName, aumId, guid, iconPath, callback); } - late final _initPtr = _lookup< - ffi.NativeFunction< + late final _initPtr = + _lookup< + ffi.NativeFunction< ffi.Bool Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - NativeNotificationCallback)>>('init'); - late final _init = _initPtr.asFunction< - bool Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + NativeNotificationCallback, + ) + > + >('init'); + late final _init = _initPtr + .asFunction< + bool Function( ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer, ffi.Pointer, - NativeNotificationCallback)>(); + NativeNotificationCallback, + ) + >(); /// Shows the XML as a notification with the given ID. See [updateNotification] for details on /// bindings. @@ -127,21 +121,29 @@ class NotificationsPluginBindings { ffi.Pointer xml, NativeStringMap bindings, ) { - return _showNotification( - plugin, - id, - xml, - bindings, - ); + return _showNotification(plugin, id, xml, bindings); } - late final _showNotificationPtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function(ffi.Pointer, ffi.Int, - ffi.Pointer, NativeStringMap)>>('showNotification'); - late final _showNotification = _showNotificationPtr.asFunction< - bool Function(ffi.Pointer, int, ffi.Pointer, - NativeStringMap)>(); + late final _showNotificationPtr = + _lookup< + ffi.NativeFunction< + ffi.Bool Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + NativeStringMap, + ) + > + >('showNotification'); + late final _showNotification = _showNotificationPtr + .asFunction< + bool Function( + ffi.Pointer, + int, + ffi.Pointer, + NativeStringMap, + ) + >(); /// Schedules the notification to be shown at the given time (as a [time_t]). bool scheduleNotification( @@ -150,21 +152,29 @@ class NotificationsPluginBindings { ffi.Pointer xml, int time, ) { - return _scheduleNotification( - plugin, - id, - xml, - time, - ); + return _scheduleNotification(plugin, id, xml, time); } - late final _scheduleNotificationPtr = _lookup< - ffi.NativeFunction< - ffi.Bool Function(ffi.Pointer, ffi.Int, - ffi.Pointer, ffi.Int)>>('scheduleNotification'); - late final _scheduleNotification = _scheduleNotificationPtr.asFunction< - bool Function( - ffi.Pointer, int, ffi.Pointer, int)>(); + late final _scheduleNotificationPtr = + _lookup< + ffi.NativeFunction< + ffi.Bool Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Int, + ) + > + >('scheduleNotification'); + late final _scheduleNotification = _scheduleNotificationPtr + .asFunction< + bool Function( + ffi.Pointer, + int, + ffi.Pointer, + int, + ) + >(); /// Updates a notification with the provided bindings after it's been shown. /// @@ -176,52 +186,51 @@ class NotificationsPluginBindings { int id, NativeStringMap bindings, ) { - return NativeUpdateResult.fromValue(_updateNotification( - plugin, - id, - bindings, - )); + return NativeUpdateResult.fromValue( + _updateNotification(plugin, id, bindings), + ); } - late final _updateNotificationPtr = _lookup< - ffi.NativeFunction< - ffi.UnsignedInt Function(ffi.Pointer, ffi.Int, - NativeStringMap)>>('updateNotification'); - late final _updateNotification = _updateNotificationPtr.asFunction< - int Function(ffi.Pointer, int, NativeStringMap)>(); + late final _updateNotificationPtr = + _lookup< + ffi.NativeFunction< + ffi.UnsignedInt Function( + ffi.Pointer, + ffi.Int, + NativeStringMap, + ) + > + >('updateNotification'); + late final _updateNotification = _updateNotificationPtr + .asFunction< + int Function(ffi.Pointer, int, NativeStringMap) + >(); /// Cancels all notifications. - void cancelAll( - ffi.Pointer plugin, - ) { - return _cancelAll( - plugin, - ); + void cancelAll(ffi.Pointer plugin) { + return _cancelAll(plugin); } late final _cancelAllPtr = _lookup)>>( - 'cancelAll'); - late final _cancelAll = - _cancelAllPtr.asFunction)>(); + 'cancelAll', + ); + late final _cancelAll = _cancelAllPtr + .asFunction)>(); /// Cancels a notification with the given ID. /// /// Only applications with "package identity" (ie, installed with an MSIX installer), can use this. - void cancelNotification( - ffi.Pointer plugin, - int id, - ) { - return _cancelNotification( - plugin, - id, - ); + void cancelNotification(ffi.Pointer plugin, int id) { + return _cancelNotification(plugin, id); } - late final _cancelNotificationPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, ffi.Int)>>('cancelNotification'); + late final _cancelNotificationPtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int) + > + >('cancelNotification'); late final _cancelNotification = _cancelNotificationPtr .asFunction, int)>(); @@ -233,71 +242,76 @@ class NotificationsPluginBindings { ffi.Pointer plugin, ffi.Pointer size, ) { - return _getActiveNotifications( - plugin, - size, - ); + return _getActiveNotifications(plugin, size); } - late final _getActiveNotificationsPtr = _lookup< - ffi.NativeFunction< + late final _getActiveNotificationsPtr = + _lookup< + ffi.NativeFunction< ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer)>>('getActiveNotifications'); - late final _getActiveNotifications = _getActiveNotificationsPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Pointer)>(); + ffi.Pointer, + ffi.Pointer, + ) + > + >('getActiveNotifications'); + late final _getActiveNotifications = _getActiveNotificationsPtr + .asFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ) + >(); /// Gets all notifications that have been scheduled but not yet shown. ffi.Pointer getPendingNotifications( ffi.Pointer plugin, ffi.Pointer size, ) { - return _getPendingNotifications( - plugin, - size, - ); + return _getPendingNotifications(plugin, size); } - late final _getPendingNotificationsPtr = _lookup< - ffi.NativeFunction< + late final _getPendingNotificationsPtr = + _lookup< + ffi.NativeFunction< ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer)>>('getPendingNotifications'); - late final _getPendingNotifications = _getPendingNotificationsPtr.asFunction< - ffi.Pointer Function( - ffi.Pointer, ffi.Pointer)>(); + ffi.Pointer, + ffi.Pointer, + ) + > + >('getPendingNotifications'); + late final _getPendingNotifications = _getPendingNotificationsPtr + .asFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ) + >(); /// Releases the memory associated with a [NativeNotificationDetails] array. - void freeDetailsArray( - ffi.Pointer ptr, - ) { - return _freeDetailsArray( - ptr, - ); + void freeDetailsArray(ffi.Pointer ptr) { + return _freeDetailsArray(ptr); } - late final _freeDetailsArrayPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer)>>('freeDetailsArray'); + late final _freeDetailsArrayPtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer) + > + >('freeDetailsArray'); late final _freeDetailsArray = _freeDetailsArrayPtr .asFunction)>(); /// Releases the memory associated with a [NativeLaunchDetails]. - void freeLaunchDetails( - NativeLaunchDetails details, - ) { - return _freeLaunchDetails( - details, - ); + void freeLaunchDetails(NativeLaunchDetails details) { + return _freeLaunchDetails(details); } late final _freeLaunchDetailsPtr = _lookup>( - 'freeLaunchDetails'); - late final _freeLaunchDetails = - _freeLaunchDetailsPtr.asFunction(); + 'freeLaunchDetails', + ); + late final _freeLaunchDetails = _freeLaunchDetailsPtr + .asFunction(); } final class NativePlugin extends ffi.Opaque {} @@ -332,10 +346,10 @@ enum NativeLaunchType { const NativeLaunchType(this.value); static NativeLaunchType fromValue(int value) => switch (value) { - 0 => notification, - 1 => action, - _ => throw ArgumentError("Unknown value for NativeLaunchType: $value"), - }; + 0 => notification, + 1 => action, + _ => throw ArgumentError("Unknown value for NativeLaunchType: $value"), + }; } /// Details about how the app was launched. @@ -365,20 +379,19 @@ enum NativeUpdateResult { const NativeUpdateResult(this.value); static NativeUpdateResult fromValue(int value) => switch (value) { - 0 => success, - 1 => failed, - 2 => notFound, - _ => - throw ArgumentError("Unknown value for NativeUpdateResult: $value"), - }; + 0 => success, + 1 => failed, + 2 => notFound, + _ => throw ArgumentError("Unknown value for NativeUpdateResult: $value"), + }; } /// A callback that is run with [NativeLaunchDetails] when a notification is pressed. /// /// This may be called at app launch or even while the app is running. -typedef NativeNotificationCallback - = ffi.Pointer>; -typedef NativeNotificationCallbackFunction = ffi.Void Function( - NativeLaunchDetails details); -typedef DartNativeNotificationCallbackFunction = void Function( - NativeLaunchDetails details); +typedef NativeNotificationCallback = + ffi.Pointer>; +typedef NativeNotificationCallbackFunction = + ffi.Void Function(NativeLaunchDetails details); +typedef DartNativeNotificationCallbackFunction = + void Function(NativeLaunchDetails details); diff --git a/flutter_local_notifications_windows/lib/src/ffi/utils.dart b/flutter_local_notifications_windows/lib/src/ffi/utils.dart index 3a63be14b..aa26caa9b 100644 --- a/flutter_local_notifications_windows/lib/src/ffi/utils.dart +++ b/flutter_local_notifications_windows/lib/src/ffi/utils.dart @@ -11,10 +11,9 @@ import 'bindings.dart'; extension NativeStringMapUtils on NativeStringMap { /// Converts this map to a typical Dart map. Map toMap() => { - for (int index = 0; index < size; index++) - entries[index].key.toDartString(): - entries[index].value.toDartString(), - }; + for (int index = 0; index < size; index++) + entries[index].key.toDartString(): entries[index].value.toDartString(), + }; } /// Gets the [NotificationResponseType] from a [NativeLaunchType]. @@ -49,8 +48,9 @@ extension MapToNativeMap on Map { int index = 0; for (final MapEntry entry in entries) { pointer.ref.entries[index].key = entry.key.toNativeUtf8(allocator: arena); - pointer.ref.entries[index].value = - entry.value.toNativeUtf8(allocator: arena); + pointer.ref.entries[index].value = entry.value.toNativeUtf8( + allocator: arena, + ); index++; } return pointer.ref; diff --git a/flutter_local_notifications_windows/lib/src/msix/ffi.dart b/flutter_local_notifications_windows/lib/src/msix/ffi.dart index a80eb122d..b79d9d0bf 100644 --- a/flutter_local_notifications_windows/lib/src/msix/ffi.dart +++ b/flutter_local_notifications_windows/lib/src/msix/ffi.dart @@ -34,8 +34,9 @@ class MsixUtils { final DynamicLibrary lib = DynamicLibrary.open( 'flutter_local_notifications_windows.dll', ); - final NotificationsPluginBindings bindings = - NotificationsPluginBindings(lib); + final NotificationsPluginBindings bindings = NotificationsPluginBindings( + lib, + ); final bool result = bindings.hasPackageIdentity(); _hasPackageIdentity = result; return result; diff --git a/flutter_local_notifications_windows/lib/src/plugin/base.dart b/flutter_local_notifications_windows/lib/src/plugin/base.dart index 4f9b633ff..a992386d0 100644 --- a/flutter_local_notifications_windows/lib/src/plugin/base.dart +++ b/flutter_local_notifications_windows/lib/src/plugin/base.dart @@ -64,11 +64,7 @@ abstract class WindowsNotificationsBase Future updateProgressBar({ required int notificationId, required WindowsProgressBar progressBar, - }) => - updateBindings( - id: notificationId, - bindings: progressBar.data, - ); + }) => updateBindings(id: notificationId, bindings: progressBar.data); /// Updates any data binding in the given notification. /// diff --git a/flutter_local_notifications_windows/lib/src/plugin/ffi.dart b/flutter_local_notifications_windows/lib/src/plugin/ffi.dart index c64a4bf22..2e9465ac9 100644 --- a/flutter_local_notifications_windows/lib/src/plugin/ffi.dart +++ b/flutter_local_notifications_windows/lib/src/plugin/ffi.dart @@ -40,8 +40,9 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { late final NotificationsPluginBindings _bindings = NotificationsPluginBindings(_library); - final DynamicLibrary _library = - DynamicLibrary.open('flutter_local_notifications_windows.dll'); + final DynamicLibrary _library = DynamicLibrary.open( + 'flutter_local_notifications_windows.dll', + ); /// A pointer to the C++ handler class. late final Pointer _plugin; @@ -62,39 +63,46 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { Future initialize( WindowsInitializationSettings settings, { DidReceiveNotificationResponseCallback? onNotificationReceived, - }) async => - using((Arena arena) { - if (_isReady) { - return true; - } - _plugin = _bindings.createPlugin(); - // The C++ code will crash if there's an invalid GUID, so check it here - if (!settings.guid.isValidGuid) { - throw ArgumentError.value( - settings.guid, - 'GUID', - 'Invalid GUID. Please use xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - ' format.\nYou can get one by searching GUID generators online', - ); - } - instance = this; - userCallback = onNotificationReceived; - final Pointer appName = - settings.appName.toNativeUtf8(allocator: arena); - final Pointer aumId = - settings.appUserModelId.toNativeUtf8(allocator: arena); - final Pointer guid = settings.guid.toNativeUtf8(allocator: arena); - final Pointer iconPath = - settings.iconPath?.toNativeUtf8(allocator: arena) ?? nullptr; - final NativeNotificationCallback callback = - NativeCallable.listener( + }) async => using((Arena arena) { + if (_isReady) { + return true; + } + _plugin = _bindings.createPlugin(); + // The C++ code will crash if there's an invalid GUID, so check it here + if (!settings.guid.isValidGuid) { + throw ArgumentError.value( + settings.guid, + 'GUID', + 'Invalid GUID. Please use xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' + ' format.\nYou can get one by searching GUID generators online', + ); + } + instance = this; + userCallback = onNotificationReceived; + final Pointer appName = settings.appName.toNativeUtf8( + allocator: arena, + ); + final Pointer aumId = settings.appUserModelId.toNativeUtf8( + allocator: arena, + ); + final Pointer guid = settings.guid.toNativeUtf8(allocator: arena); + final Pointer iconPath = + settings.iconPath?.toNativeUtf8(allocator: arena) ?? nullptr; + final NativeNotificationCallback callback = + NativeCallable.listener( _globalLaunchCallback, ).nativeFunction; - final bool result = - _bindings.init(_plugin, appName, aumId, guid, iconPath, callback); - _isReady = result; - return result; - }); + final bool result = _bindings.init( + _plugin, + appName, + aumId, + guid, + iconPath, + callback, + ); + _isReady = result; + return result; + }); @override void dispose() { @@ -152,34 +160,36 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { ); } final Pointer length = arena(); - final Pointer array = - _bindings.getActiveNotifications(_plugin, length); - final List result = - array.asActiveNotifications(length.value); + final Pointer array = _bindings + .getActiveNotifications(_plugin, length); + final List result = array.asActiveNotifications( + length.value, + ); _bindings.freeDetailsArray(array); return result; }); @override Future> - pendingNotificationRequests() async => using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - final Pointer length = arena(); - final Pointer array = - _bindings.getPendingNotifications(_plugin, length); - final List result = - array.asPendingRequests(length.value); - _bindings.freeDetailsArray(array); - return result; - }); + pendingNotificationRequests() async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + final Pointer length = arena(); + final Pointer array = _bindings + .getPendingNotifications(_plugin, length); + final List result = array.asPendingRequests( + length.value, + ); + _bindings.freeDetailsArray(array); + return result; + }); @override Future - getNotificationAppLaunchDetails() async { + getNotificationAppLaunchDetails() async { if (!_isReady) { throw StateError( 'Flutter Local Notifications must be initialized before use', @@ -226,64 +236,71 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { } @override - Future show(int id, String? title, String? body, - {String? payload, WindowsNotificationDetails? details}) async => - using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - final Map bindings = { - if (details != null) ...details.bindings, - for (final WindowsProgressBar progressBar - in details?.progressBars ?? []) - ...progressBar.data, - }; - final NativeStringMap nativeMap = bindings.toNativeMap(arena); - final String xml = notificationToXml( - title: title, - body: body, - payload: payload, - details: details, - ); - final bool result = _bindings.showNotification( - _plugin, - id, - xml.toNativeUtf8(allocator: arena), - nativeMap, - ); - if (!result) { - throw Exception( - 'Flutter Local Notifications could not show notification', - ); - } - }); + Future show( + int id, + String? title, + String? body, { + String? payload, + WindowsNotificationDetails? details, + }) async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + final Map bindings = { + if (details != null) ...details.bindings, + for (final WindowsProgressBar progressBar + in details?.progressBars ?? []) + ...progressBar.data, + }; + final NativeStringMap nativeMap = bindings.toNativeMap(arena); + final String xml = notificationToXml( + title: title, + body: body, + payload: payload, + details: details, + ); + final bool result = _bindings.showNotification( + _plugin, + id, + xml.toNativeUtf8(allocator: arena), + nativeMap, + ); + if (!result) { + throw Exception( + 'Flutter Local Notifications could not show notification', + ); + } + }); @override Future showRawXml({ required int id, required String xml, Map bindings = const {}, - }) async => - using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - final bool result = _bindings.showNotification(_plugin, id, - xml.toNativeUtf8(allocator: arena), bindings.toNativeMap(arena)); - if (!result) { - throw ArgumentError('Flutter Local Notifications: Invalid XML'); - } - }); + }) async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + final bool result = _bindings.showNotification( + _plugin, + id, + xml.toNativeUtf8(allocator: arena), + bindings.toNativeMap(arena), + ); + if (!result) { + throw ArgumentError('Flutter Local Notifications: Invalid XML'); + } + }); @override bool isValidXml(String xml) => using((Arena arena) { - final Pointer nativeXml = xml.toNativeUtf8(allocator: arena); - return _bindings.isValidXml(nativeXml); - }); + final Pointer nativeXml = xml.toNativeUtf8(allocator: arena); + return _bindings.isValidXml(nativeXml); + }); @override Future zonedSchedule( @@ -293,76 +310,74 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { TZDateTime scheduledDate, WindowsNotificationDetails? details, { String? payload, - }) async => - using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - if (scheduledDate.isBefore(DateTime.now())) { - throw ArgumentError( - 'Flutter Local Notifications cannot' - ' schedule notifications in the past', - ); - } - final String xml = notificationToXml( - title: title, - body: body, - payload: payload, - details: details, - ); - final int secondsSinceEpoch = - scheduledDate.millisecondsSinceEpoch ~/ 1000; - _bindings.scheduleNotification( - _plugin, - id, - xml.toNativeUtf8(allocator: arena), - secondsSinceEpoch, - ); - }); + }) async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + if (scheduledDate.isBefore(DateTime.now())) { + throw ArgumentError( + 'Flutter Local Notifications cannot' + ' schedule notifications in the past', + ); + } + final String xml = notificationToXml( + title: title, + body: body, + payload: payload, + details: details, + ); + final int secondsSinceEpoch = scheduledDate.millisecondsSinceEpoch ~/ 1000; + _bindings.scheduleNotification( + _plugin, + id, + xml.toNativeUtf8(allocator: arena), + secondsSinceEpoch, + ); + }); @override Future zonedScheduleRawXml( int id, String xml, TZDateTime scheduledDate, - ) async => - using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - if (scheduledDate.isBefore(DateTime.now())) { - throw ArgumentError( - 'Flutter Local Notifications cannot' - ' schedule notifications in the past', - ); - } - final int secondsSinceEpoch = - scheduledDate.millisecondsSinceEpoch ~/ 1000; - _bindings.scheduleNotification( - _plugin, - id, - xml.toNativeUtf8(allocator: arena), - secondsSinceEpoch, - ); - }); + ) async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + if (scheduledDate.isBefore(DateTime.now())) { + throw ArgumentError( + 'Flutter Local Notifications cannot' + ' schedule notifications in the past', + ); + } + final int secondsSinceEpoch = scheduledDate.millisecondsSinceEpoch ~/ 1000; + _bindings.scheduleNotification( + _plugin, + id, + xml.toNativeUtf8(allocator: arena), + secondsSinceEpoch, + ); + }); @override Future updateBindings({ required int id, required Map bindings, - }) async => - using((Arena arena) { - if (!_isReady) { - throw StateError( - 'Flutter Local Notifications must be initialized before use', - ); - } - final NativeUpdateResult result = _bindings.updateNotification( - _plugin, id, bindings.toNativeMap(arena)); - return getUpdateResult(result); - }); + }) async => using((Arena arena) { + if (!_isReady) { + throw StateError( + 'Flutter Local Notifications must be initialized before use', + ); + } + final NativeUpdateResult result = _bindings.updateNotification( + _plugin, + id, + bindings.toNativeMap(arena), + ); + return getUpdateResult(result); + }); } diff --git a/flutter_local_notifications_windows/lib/src/plugin/stub.dart b/flutter_local_notifications_windows/lib/src/plugin/stub.dart index cafce4f8b..446757122 100644 --- a/flutter_local_notifications_windows/lib/src/plugin/stub.dart +++ b/flutter_local_notifications_windows/lib/src/plugin/stub.dart @@ -28,11 +28,11 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { @override Future - getNotificationAppLaunchDetails() async => null; + getNotificationAppLaunchDetails() async => null; @override Future> - pendingNotificationRequests() async => []; + pendingNotificationRequests() async => []; @override Future periodicallyShow( @@ -87,8 +87,7 @@ class FlutterLocalNotificationsWindows extends WindowsNotificationsBase { Future updateBindings({ required int id, required Map bindings, - }) async => - NotificationUpdateResult.success; + }) async => NotificationUpdateResult.success; @override bool isValidXml(String xml) => false; diff --git a/flutter_local_notifications_windows/test/bindings_test.dart b/flutter_local_notifications_windows/test/bindings_test.dart index 0f1c921ab..91f363e38 100644 --- a/flutter_local_notifications_windows/test/bindings_test.dart +++ b/flutter_local_notifications_windows/test/bindings_test.dart @@ -13,46 +13,54 @@ const Map bindings = { }; void main() => group('Bindings', () { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - setUpAll(() => plugin.initialize(settings)); - tearDownAll(() async { - await plugin.cancelAll(); - plugin.dispose(); - }); + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + setUpAll(() => plugin.initialize(settings)); + tearDownAll(() async { + await plugin.cancelAll(); + plugin.dispose(); + }); - test('work in simple cases', () async { - await plugin.show(500, '{title}', '{body}'); - final NotificationUpdateResult result = - await plugin.updateBindings(id: 500, bindings: bindings); - expect(result, NotificationUpdateResult.success); - }); + test('work in simple cases', () async { + await plugin.show(500, '{title}', '{body}'); + final NotificationUpdateResult result = await plugin.updateBindings( + id: 500, + bindings: bindings, + ); + expect(result, NotificationUpdateResult.success); + }); - test('fail when ID is not found in simple cases', () async { - await plugin.show(501, '{title}', '{body}'); - final NotificationUpdateResult result = - await plugin.updateBindings(id: 599, bindings: bindings); - expect(result, NotificationUpdateResult.notFound); - }); + test('fail when ID is not found in simple cases', () async { + await plugin.show(501, '{title}', '{body}'); + final NotificationUpdateResult result = await plugin.updateBindings( + id: 599, + bindings: bindings, + ); + expect(result, NotificationUpdateResult.notFound); + }); - test('are included in show()', () async { - await plugin.show( - 502, - '{title}', - '{body}', - details: const WindowsNotificationDetails(bindings: bindings), - ); - }); + test('are included in show()', () async { + await plugin.show( + 502, + '{title}', + '{body}', + details: const WindowsNotificationDetails(bindings: bindings), + ); + }); - test('fail when notification has been cancelled', () async { - await Future.delayed(const Duration(milliseconds: 200)); - await plugin.show(503, '{title}', '{body}'); - final NotificationUpdateResult result = - await plugin.updateBindings(id: 503, bindings: bindings); - expect(result, NotificationUpdateResult.success); - await plugin.cancelAll(); - final NotificationUpdateResult result2 = - await plugin.updateBindings(id: 503, bindings: bindings); - expect(result2, NotificationUpdateResult.notFound); - }); - }); + test('fail when notification has been cancelled', () async { + await Future.delayed(const Duration(milliseconds: 200)); + await plugin.show(503, '{title}', '{body}'); + final NotificationUpdateResult result = await plugin.updateBindings( + id: 503, + bindings: bindings, + ); + expect(result, NotificationUpdateResult.success); + await plugin.cancelAll(); + final NotificationUpdateResult result2 = await plugin.updateBindings( + id: 503, + bindings: bindings, + ); + expect(result2, NotificationUpdateResult.notFound); + }); +}); diff --git a/flutter_local_notifications_windows/test/details_test.dart b/flutter_local_notifications_windows/test/details_test.dart index ea90159cd..d42174e7b 100644 --- a/flutter_local_notifications_windows/test/details_test.dart +++ b/flutter_local_notifications_windows/test/details_test.dart @@ -12,246 +12,303 @@ extension PluginUtils on FlutterLocalNotificationsWindows { static int id = 15; void testDetails(WindowsNotificationDetails details) => expect( - isValidXml( - notificationToXml( - title: 'title', - body: 'body', - payload: 'payload', - details: details, - ), - ), - isTrue, - ); + isValidXml( + notificationToXml( + title: 'title', + body: 'body', + payload: 'payload', + details: details, + ), + ), + isTrue, + ); } void main() => group('Details:', () { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - setUpAll(() => plugin.initialize(settings)); - tearDownAll(() async { - await plugin.cancelAll(); - plugin.dispose(); - }); + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + setUpAll(() => plugin.initialize(settings)); + tearDownAll(() async { + await plugin.cancelAll(); + plugin.dispose(); + }); - test('No details', () async { - expect(plugin.show(100, null, null), completes); - expect(plugin.show(101, 'Title', null), completes); - expect(plugin.show(102, null, 'Body'), completes); - expect(plugin.show(103, 'Title', 'Body'), completes); - expect(plugin.show(-1, 'Negative ID', 'Body'), completes); - }); + test('No details', () async { + expect(plugin.show(100, null, null), completes); + expect(plugin.show(101, 'Title', null), completes); + expect(plugin.show(102, null, 'Body'), completes); + expect(plugin.show(103, 'Title', 'Body'), completes); + expect(plugin.show(-1, 'Negative ID', 'Body'), completes); + }); - test( - 'Simple details', - () async => plugin - ..testDetails(const WindowsNotificationDetails()) - ..testDetails( - const WindowsNotificationDetails(subtitle: 'Subtitle')) - ..testDetails(const WindowsNotificationDetails( - duration: WindowsNotificationDuration.long)) - ..testDetails(const WindowsNotificationDetails( - scenario: WindowsNotificationScenario.reminder)) - ..testDetails(WindowsNotificationDetails(timestamp: DateTime.now())) - ..testDetails(const WindowsNotificationDetails( - subtitle: '{message}', - bindings: {'message': 'Hello, Mr. Person'}))); + test( + 'Simple details', + () async => plugin + ..testDetails(const WindowsNotificationDetails()) + ..testDetails(const WindowsNotificationDetails(subtitle: 'Subtitle')) + ..testDetails( + const WindowsNotificationDetails( + duration: WindowsNotificationDuration.long, + ), + ) + ..testDetails( + const WindowsNotificationDetails( + scenario: WindowsNotificationScenario.reminder, + ), + ) + ..testDetails(WindowsNotificationDetails(timestamp: DateTime.now())) + ..testDetails( + const WindowsNotificationDetails( + subtitle: '{message}', + bindings: {'message': 'Hello, Mr. Person'}, + ), + ), + ); - test('Actions', () { - const WindowsAction simpleAction = - WindowsAction(content: 'Press me', arguments: '123'); - final WindowsAction complexAction = WindowsAction( - content: 'content', - arguments: 'args', - activationBehavior: WindowsNotificationBehavior.pendingUpdate, - buttonStyle: WindowsButtonStyle.success, - inputId: 'input-id', - tooltip: 'tooltip', - imageUri: WindowsImage.getAssetUri('test/icon.png'), - ); - plugin - ..testDetails(const WindowsNotificationDetails( - actions: [simpleAction])) - ..testDetails(WindowsNotificationDetails( - actions: [complexAction])) - ..testDetails(WindowsNotificationDetails( - actions: List.filled(5, simpleAction))); - expect( - () => notificationToXml( - details: WindowsNotificationDetails( - actions: List.filled(6, simpleAction), - )), - throwsArgumentError, - ); - }); + test('Actions', () { + const WindowsAction simpleAction = WindowsAction( + content: 'Press me', + arguments: '123', + ); + final WindowsAction complexAction = WindowsAction( + content: 'content', + arguments: 'args', + activationBehavior: WindowsNotificationBehavior.pendingUpdate, + buttonStyle: WindowsButtonStyle.success, + inputId: 'input-id', + tooltip: 'tooltip', + imageUri: WindowsImage.getAssetUri('test/icon.png'), + ); + plugin + ..testDetails( + const WindowsNotificationDetails( + actions: [simpleAction], + ), + ) + ..testDetails( + WindowsNotificationDetails(actions: [complexAction]), + ) + ..testDetails( + WindowsNotificationDetails( + actions: List.filled(5, simpleAction), + ), + ); + expect( + () => notificationToXml( + details: WindowsNotificationDetails( + actions: List.filled(6, simpleAction), + ), + ), + throwsArgumentError, + ); + }); - test( - 'Audio', - () => plugin - ..testDetails(WindowsNotificationDetails( - audio: WindowsNotificationAudio.silent())) - ..testDetails(WindowsNotificationDetails( - audio: WindowsNotificationAudio.preset( - sound: WindowsNotificationSound.call10)))); + test( + 'Audio', + () => plugin + ..testDetails( + WindowsNotificationDetails(audio: WindowsNotificationAudio.silent()), + ) + ..testDetails( + WindowsNotificationDetails( + audio: WindowsNotificationAudio.preset( + sound: WindowsNotificationSound.call10, + ), + ), + ), + ); - test('Rows', () { - const WindowsColumn emptyColumn = - WindowsColumn([]); - final WindowsImage image = WindowsImage( - WindowsImage.getAssetUri('test/icon.png'), - altText: 'an icon', - ); - const WindowsNotificationText text = - WindowsNotificationText(text: 'Text'); - final WindowsColumn simpleColumn = - WindowsColumn([image, text]); - final WindowsRow bigRow = WindowsRow( - List.filled(5, simpleColumn), - ); - plugin - ..testDetails(const WindowsNotificationDetails()) - ..testDetails(const WindowsNotificationDetails( - rows: [WindowsRow([])])) - ..testDetails(const WindowsNotificationDetails(rows: [ - WindowsRow([emptyColumn]) - ])) - ..testDetails(WindowsNotificationDetails(rows: [ - WindowsRow([simpleColumn]) - ])) - ..testDetails(WindowsNotificationDetails(rows: [bigRow])) - ..testDetails(WindowsNotificationDetails( - rows: List.filled(5, bigRow))); - }); + test('Rows', () { + const WindowsColumn emptyColumn = WindowsColumn( + [], + ); + final WindowsImage image = WindowsImage( + WindowsImage.getAssetUri('test/icon.png'), + altText: 'an icon', + ); + const WindowsNotificationText text = WindowsNotificationText(text: 'Text'); + final WindowsColumn simpleColumn = WindowsColumn([ + image, + text, + ]); + final WindowsRow bigRow = WindowsRow( + List.filled(5, simpleColumn), + ); + plugin + ..testDetails(const WindowsNotificationDetails()) + ..testDetails( + const WindowsNotificationDetails( + rows: [WindowsRow([])], + ), + ) + ..testDetails( + const WindowsNotificationDetails( + rows: [ + WindowsRow([emptyColumn]), + ], + ), + ) + ..testDetails( + WindowsNotificationDetails( + rows: [ + WindowsRow([simpleColumn]), + ], + ), + ) + ..testDetails(WindowsNotificationDetails(rows: [bigRow])) + ..testDetails( + WindowsNotificationDetails(rows: List.filled(5, bigRow)), + ); + }); - test('Header', () async { - const WindowsHeader header = WindowsHeader( - id: 'header1', - title: 'Header 1', - arguments: 'args1', - activation: WindowsHeaderActivation.foreground, - ); - plugin - ..testDetails(const WindowsNotificationDetails(header: header)) - ..testDetails(const WindowsNotificationDetails(header: header)); - }); + test('Header', () async { + const WindowsHeader header = WindowsHeader( + id: 'header1', + title: 'Header 1', + arguments: 'args1', + activation: WindowsHeaderActivation.foreground, + ); + plugin + ..testDetails(const WindowsNotificationDetails(header: header)) + ..testDetails(const WindowsNotificationDetails(header: header)); + }); - test('Images', () async { - final WindowsImage simpleImage = WindowsImage( - WindowsImage.getAssetUri('asset.png'), - altText: 'an icon', - ); - final WindowsImage complexImage = WindowsImage( - Uri.parse('https://picsum.photos/500'), - altText: 'an icon', - addQueryParams: true, - crop: WindowsImageCrop.circle, - placement: WindowsImagePlacement.appLogoOverride, - ); - plugin - ..testDetails( - WindowsNotificationDetails(images: [simpleImage])) - ..testDetails(WindowsNotificationDetails( - images: [simpleImage, complexImage])) - ..testDetails( - WindowsNotificationDetails( - images: List.filled(6, simpleImage), - ), - ); - }); + test('Images', () async { + final WindowsImage simpleImage = WindowsImage( + WindowsImage.getAssetUri('asset.png'), + altText: 'an icon', + ); + final WindowsImage complexImage = WindowsImage( + Uri.parse('https://picsum.photos/500'), + altText: 'an icon', + addQueryParams: true, + crop: WindowsImageCrop.circle, + placement: WindowsImagePlacement.appLogoOverride, + ); + plugin + ..testDetails( + WindowsNotificationDetails(images: [simpleImage]), + ) + ..testDetails( + WindowsNotificationDetails( + images: [simpleImage, complexImage], + ), + ) + ..testDetails( + WindowsNotificationDetails( + images: List.filled(6, simpleImage), + ), + ); + }); - test('Inputs', () async { - const WindowsTextInput textInput = WindowsTextInput( - id: 'input', - placeHolderContent: 'Text hint', - title: 'Text title', - ); - const WindowsSelectionInput selection = WindowsSelectionInput( - id: 'input', - items: [ - WindowsSelection(id: 'item1', content: 'Item 1'), - WindowsSelection(id: 'item2', content: 'Item 2'), - WindowsSelection(id: 'item3', content: 'Item 3'), - ], - ); - const WindowsAction action = WindowsAction( - content: 'Submit', - arguments: 'submit', - inputId: 'input', - ); - plugin - ..testDetails(const WindowsNotificationDetails( - inputs: [textInput])) - ..testDetails(const WindowsNotificationDetails( - inputs: [selection])) - ..testDetails( - WindowsNotificationDetails( - inputs: List.filled(5, textInput), - ), - ) - ..testDetails(const WindowsNotificationDetails( - inputs: [textInput], - actions: [action])) - ..testDetails(const WindowsNotificationDetails( - inputs: [selection, textInput], - actions: [action])); - expect( - () => notificationToXml( - details: WindowsNotificationDetails( - inputs: List.filled(6, textInput), - ), - ), - throwsArgumentError, - ); - }); + test('Inputs', () async { + const WindowsTextInput textInput = WindowsTextInput( + id: 'input', + placeHolderContent: 'Text hint', + title: 'Text title', + ); + const WindowsSelectionInput selection = WindowsSelectionInput( + id: 'input', + items: [ + WindowsSelection(id: 'item1', content: 'Item 1'), + WindowsSelection(id: 'item2', content: 'Item 2'), + WindowsSelection(id: 'item3', content: 'Item 3'), + ], + ); + const WindowsAction action = WindowsAction( + content: 'Submit', + arguments: 'submit', + inputId: 'input', + ); + plugin + ..testDetails( + const WindowsNotificationDetails(inputs: [textInput]), + ) + ..testDetails( + const WindowsNotificationDetails(inputs: [selection]), + ) + ..testDetails( + WindowsNotificationDetails( + inputs: List.filled(5, textInput), + ), + ) + ..testDetails( + const WindowsNotificationDetails( + inputs: [textInput], + actions: [action], + ), + ) + ..testDetails( + const WindowsNotificationDetails( + inputs: [selection, textInput], + actions: [action], + ), + ); + expect( + () => notificationToXml( + details: WindowsNotificationDetails( + inputs: List.filled(6, textInput), + ), + ), + throwsArgumentError, + ); + }); - test('Progress', () async { - final WindowsProgressBar simple = WindowsProgressBar( - id: 'simple', - status: 'Testing...', - value: 0.25, - ); - final WindowsProgressBar complex = WindowsProgressBar( - id: 'complex', - status: 'Testing...', - value: 0.75, - label: 'Progress label', - title: 'Progress title', - ); - final WindowsProgressBar dynamic = WindowsProgressBar( - id: 'dynamic', - status: 'Testing...', - value: 0, - ); - plugin - ..testDetails(WindowsNotificationDetails( - progressBars: [simple])) - ..testDetails(WindowsNotificationDetails( - progressBars: [complex])) - ..testDetails(WindowsNotificationDetails( - progressBars: [simple, complex])) - ..testDetails( - WindowsNotificationDetails( - progressBars: List.filled(6, simple), - ), - ); - await plugin.show( - 201, - null, - null, - details: WindowsNotificationDetails( - progressBars: [dynamic], - ), - ); - for (double i = 0; i <= 1.5; i += 0.05) { - dynamic.value = i; - final NotificationUpdateResult result = await plugin - .updateProgressBar(notificationId: 201, progressBar: dynamic); - expect(result, NotificationUpdateResult.success); - await Future.delayed(const Duration(milliseconds: 10)); - } - expect( - await plugin.updateProgressBar( - notificationId: 202, progressBar: dynamic), - NotificationUpdateResult.notFound, - ); - }); - }); + test('Progress', () async { + final WindowsProgressBar simple = WindowsProgressBar( + id: 'simple', + status: 'Testing...', + value: 0.25, + ); + final WindowsProgressBar complex = WindowsProgressBar( + id: 'complex', + status: 'Testing...', + value: 0.75, + label: 'Progress label', + title: 'Progress title', + ); + final WindowsProgressBar dynamic = WindowsProgressBar( + id: 'dynamic', + status: 'Testing...', + value: 0, + ); + plugin + ..testDetails( + WindowsNotificationDetails(progressBars: [simple]), + ) + ..testDetails( + WindowsNotificationDetails(progressBars: [complex]), + ) + ..testDetails( + WindowsNotificationDetails( + progressBars: [simple, complex], + ), + ) + ..testDetails( + WindowsNotificationDetails( + progressBars: List.filled(6, simple), + ), + ); + await plugin.show( + 201, + null, + null, + details: WindowsNotificationDetails( + progressBars: [dynamic], + ), + ); + for (double i = 0; i <= 1.5; i += 0.05) { + dynamic.value = i; + final NotificationUpdateResult result = await plugin.updateProgressBar( + notificationId: 201, + progressBar: dynamic, + ); + expect(result, NotificationUpdateResult.success); + await Future.delayed(const Duration(milliseconds: 10)); + } + expect( + await plugin.updateProgressBar(notificationId: 202, progressBar: dynamic), + NotificationUpdateResult.notFound, + ); + }); +}); diff --git a/flutter_local_notifications_windows/test/plugin_test.dart b/flutter_local_notifications_windows/test/plugin_test.dart index 7564ec322..174df6f1d 100644 --- a/flutter_local_notifications_windows/test/plugin_test.dart +++ b/flutter_local_notifications_windows/test/plugin_test.dart @@ -6,10 +6,10 @@ import 'package:timezone/standalone.dart'; const WindowsInitializationSettings goodSettings = WindowsInitializationSettings( - appName: 'test', - appUserModelId: 'com.test.test', - guid: 'a8c22b55-049e-422f-b30f-863694de08c8', -); + appName: 'test', + appUserModelId: 'com.test.test', + guid: 'a8c22b55-049e-422f-b30f-863694de08c8', + ); const WindowsInitializationSettings badSettings = WindowsInitializationSettings( appName: 'test', @@ -18,91 +18,93 @@ const WindowsInitializationSettings badSettings = WindowsInitializationSettings( ); void main() => group('Plugin', () { - setUpAll(initializeTimeZones); + setUpAll(initializeTimeZones); - test('initializes safely', () async { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - final bool result = await plugin.initialize(goodSettings); - expect(result, isTrue); - plugin.dispose(); - }); + test('initializes safely', () async { + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + final bool result = await plugin.initialize(goodSettings); + expect(result, isTrue); + plugin.dispose(); + }); - test('catches bad GUIDs', () async { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - expect(plugin.initialize(badSettings), throwsArgumentError); - plugin.dispose(); - }); + test('catches bad GUIDs', () async { + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + expect(plugin.initialize(badSettings), throwsArgumentError); + plugin.dispose(); + }); - test('cannot be used before initializing', () async { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - final WindowsProgressBar progress = - WindowsProgressBar(id: 'progress', status: 'Testing', value: 0); - final TZDateTime now = TZDateTime.local(2024, 7, 18); - expect(plugin.cancel(0), throwsStateError); - expect(plugin.cancelAll(), throwsStateError); - expect(plugin.getActiveNotifications(), throwsStateError); - expect(plugin.getNotificationAppLaunchDetails(), throwsStateError); - expect(plugin.pendingNotificationRequests(), throwsStateError); - expect(plugin.show(0, 'Title', 'Body'), throwsStateError); - expect(plugin.showRawXml(id: 0, xml: ''), throwsStateError); - expect( - plugin.updateBindings(id: 0, bindings: {}), - throwsStateError, - ); - expect( - plugin.updateProgressBar(progressBar: progress, notificationId: 0), - throwsStateError, - ); - expect( - plugin.zonedSchedule(0, null, null, now, null), - throwsStateError, - ); - plugin.dispose(); - }); + test('cannot be used before initializing', () async { + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + final WindowsProgressBar progress = WindowsProgressBar( + id: 'progress', + status: 'Testing', + value: 0, + ); + final TZDateTime now = TZDateTime.local(2024, 7, 18); + expect(plugin.cancel(0), throwsStateError); + expect(plugin.cancelAll(), throwsStateError); + expect(plugin.getActiveNotifications(), throwsStateError); + expect(plugin.getNotificationAppLaunchDetails(), throwsStateError); + expect(plugin.pendingNotificationRequests(), throwsStateError); + expect(plugin.show(0, 'Title', 'Body'), throwsStateError); + expect(plugin.showRawXml(id: 0, xml: ''), throwsStateError); + expect( + plugin.updateBindings(id: 0, bindings: {}), + throwsStateError, + ); + expect( + plugin.updateProgressBar(progressBar: progress, notificationId: 0), + throwsStateError, + ); + expect(plugin.zonedSchedule(0, null, null, now, null), throwsStateError); + plugin.dispose(); + }); - test('cannot be used after disposed', () async { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - final WindowsProgressBar progress = - WindowsProgressBar(id: 'progress', status: 'Testing', value: 0); - final TZDateTime now = TZDateTime.local(2024, 7, 18); - await plugin.initialize(goodSettings); - plugin.dispose(); - expect(plugin.cancel(0), throwsStateError); - expect(plugin.cancelAll(), throwsStateError); - expect(plugin.getActiveNotifications(), throwsStateError); - expect(plugin.getNotificationAppLaunchDetails(), throwsStateError); - expect(plugin.pendingNotificationRequests(), throwsStateError); - expect(plugin.show(0, 'Title', 'Body'), throwsStateError); - expect(plugin.showRawXml(id: 0, xml: ''), throwsStateError); - expect( - plugin.updateBindings(id: 0, bindings: {}), - throwsStateError, - ); - expect( - plugin.updateProgressBar(progressBar: progress, notificationId: 0), - throwsStateError, - ); - expect( - plugin.zonedSchedule(0, null, null, now, null), throwsStateError); - plugin.dispose(); - }); + test('cannot be used after disposed', () async { + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + final WindowsProgressBar progress = WindowsProgressBar( + id: 'progress', + status: 'Testing', + value: 0, + ); + final TZDateTime now = TZDateTime.local(2024, 7, 18); + await plugin.initialize(goodSettings); + plugin.dispose(); + expect(plugin.cancel(0), throwsStateError); + expect(plugin.cancelAll(), throwsStateError); + expect(plugin.getActiveNotifications(), throwsStateError); + expect(plugin.getNotificationAppLaunchDetails(), throwsStateError); + expect(plugin.pendingNotificationRequests(), throwsStateError); + expect(plugin.show(0, 'Title', 'Body'), throwsStateError); + expect(plugin.showRawXml(id: 0, xml: ''), throwsStateError); + expect( + plugin.updateBindings(id: 0, bindings: {}), + throwsStateError, + ); + expect( + plugin.updateProgressBar(progressBar: progress, notificationId: 0), + throwsStateError, + ); + expect(plugin.zonedSchedule(0, null, null, now, null), throwsStateError); + plugin.dispose(); + }); - test('does not support repeating notifications', () async { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - await plugin.initialize(goodSettings); - expect( - plugin.periodicallyShow(0, null, null, RepeatInterval.everyMinute), - throwsUnsupportedError, - ); - expect( - plugin.periodicallyShowWithDuration(0, null, null, Duration.zero), - throwsUnsupportedError, - ); - plugin.dispose(); - }); - }); + test('does not support repeating notifications', () async { + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + await plugin.initialize(goodSettings); + expect( + plugin.periodicallyShow(0, null, null, RepeatInterval.everyMinute), + throwsUnsupportedError, + ); + expect( + plugin.periodicallyShowWithDuration(0, null, null, Duration.zero), + throwsUnsupportedError, + ); + plugin.dispose(); + }); +}); diff --git a/flutter_local_notifications_windows/test/scheduled_test.dart b/flutter_local_notifications_windows/test/scheduled_test.dart index 08e2cbbf9..1955e90ae 100644 --- a/flutter_local_notifications_windows/test/scheduled_test.dart +++ b/flutter_local_notifications_windows/test/scheduled_test.dart @@ -4,32 +4,37 @@ import 'package:timezone/data/latest_all.dart'; import 'package:timezone/standalone.dart'; const WindowsInitializationSettings settings = WindowsInitializationSettings( - appName: 'Test app', - appUserModelId: 'com.test.test', - guid: 'a8c22b55-049e-422f-b30f-863694de08c8'); + appName: 'Test app', + appUserModelId: 'com.test.test', + guid: 'a8c22b55-049e-422f-b30f-863694de08c8', +); void main() => group('Schedules', () { - final FlutterLocalNotificationsWindows plugin = - FlutterLocalNotificationsWindows(); - setUpAll(initializeTimeZones); - setUpAll(() => plugin.initialize(settings)); - tearDownAll(() async { - await plugin.cancelAll(); - plugin.dispose(); - }); + final FlutterLocalNotificationsWindows plugin = + FlutterLocalNotificationsWindows(); + setUpAll(initializeTimeZones); + setUpAll(() => plugin.initialize(settings)); + tearDownAll(() async { + await plugin.cancelAll(); + plugin.dispose(); + }); - Future countPending() async => - (await plugin.pendingNotificationRequests()).length; - late final Location location = getLocation('US/Eastern'); + Future countPending() async => + (await plugin.pendingNotificationRequests()).length; + late final Location location = getLocation('US/Eastern'); - test('do not work with earlier time', () async { - final TZDateTime now = TZDateTime.now(location); - final TZDateTime earlier = now.subtract(const Duration(days: 1)); - await plugin.cancelAll(); - expect(await countPending(), 0); - expect(plugin.zonedSchedule(302, null, null, now, null), - throwsArgumentError); - expect(plugin.zonedSchedule(302, null, null, earlier, null), - throwsArgumentError); - }); - }); + test('do not work with earlier time', () async { + final TZDateTime now = TZDateTime.now(location); + final TZDateTime earlier = now.subtract(const Duration(days: 1)); + await plugin.cancelAll(); + expect(await countPending(), 0); + expect( + plugin.zonedSchedule(302, null, null, now, null), + throwsArgumentError, + ); + expect( + plugin.zonedSchedule(302, null, null, earlier, null), + throwsArgumentError, + ); + }); +}); From dedaa382b5cb58e17565d58d225baae9ce66ef3c Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:32:05 +1100 Subject: [PATCH 8/9] fixed issues found by analyser --- .../platform_flutter_local_notifications.dart | 51 ++++++++++--------- .../lib/src/notification_info.dart | 2 +- .../lib/src/helpers.dart | 3 +- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart index 564038674..96ce31071 100644 --- a/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart +++ b/flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart @@ -58,26 +58,28 @@ class MethodChannelFlutterLocalNotificationsPlugin result != null && result.containsKey('notificationResponse') ? result['notificationResponse'] : null; - return result == null - ? null - : NotificationAppLaunchDetails( - result['notificationLaunchedApp'], - notificationResponse: notificationResponse == null - ? null - : NotificationResponse( - id: notificationResponse['notificationId'], - actionId: notificationResponse['actionId'], - input: notificationResponse['input'], - notificationResponseType: NotificationResponseType - .values[notificationResponse['notificationResponseType']], - payload: notificationResponse.containsKey('payload') - ? notificationResponse['payload'] - : null, - data: Map.from( - notificationResponse['data'] ?? {}, - ), - ), - ); + if (result == null) { + return null; + } else { + return NotificationAppLaunchDetails( + result['notificationLaunchedApp'], + notificationResponse: notificationResponse == null + ? null + : NotificationResponse( + id: notificationResponse['notificationId'], + actionId: notificationResponse['actionId'], + input: notificationResponse['input'], + notificationResponseType: NotificationResponseType + .values[notificationResponse['notificationResponseType']], + payload: notificationResponse.containsKey('payload') + ? notificationResponse['payload'] + : null, + data: Map.from( + notificationResponse['data'] ?? {}, + ), + ), + ); + } } @override @@ -85,8 +87,8 @@ class MethodChannelFlutterLocalNotificationsPlugin final List>? pendingNotifications = await _channel .invokeListMethod('pendingNotificationRequests'); return pendingNotifications - // ignore: always_specify_types ?.map( + // ignore: always_specify_types (p) => PendingNotificationRequest( p['id'], p['title'], @@ -103,8 +105,8 @@ class MethodChannelFlutterLocalNotificationsPlugin final List>? activeNotifications = await _channel .invokeListMethod('getActiveNotifications'); return activeNotifications - // ignore: always_specify_types ?.map( + // ignore: always_specify_types (p) => ActiveNotification( id: p['id'], channelId: p['channelId'], @@ -334,7 +336,8 @@ class AndroidFlutterLocalNotificationsPlugin throw ArgumentError.value( id, 'id', - 'The id of a notification used for an Android foreground service must not be 0!', + 'The id of a notification used for an Android foreground service must ' + 'not be 0!', ); // ignore: lines_longer_than_80_chars } if (foregroundServiceTypes?.isEmpty ?? false) { @@ -584,8 +587,8 @@ class AndroidFlutterLocalNotificationsPlugin .invokeListMethod('getNotificationChannels'); return notificationChannels - // ignore: always_specify_types ?.map( + // ignore: always_specify_types (a) => AndroidNotificationChannel( a['id'], a['name'], diff --git a/flutter_local_notifications_linux/lib/src/notification_info.dart b/flutter_local_notifications_linux/lib/src/notification_info.dart index b5833eeb9..51bd768ce 100644 --- a/flutter_local_notifications_linux/lib/src/notification_info.dart +++ b/flutter_local_notifications_linux/lib/src/notification_info.dart @@ -15,8 +15,8 @@ class LinuxNotificationInfo { factory LinuxNotificationInfo.fromJson(Map json) { final List? actionsJson = json['actions'] as List?; final List? actions = actionsJson - // ignore: avoid_annotating_with_dynamic ?.map( + // ignore: avoid_annotating_with_dynamic (dynamic json) => LinuxNotificationActionInfo.fromJson( json as Map, ), diff --git a/flutter_local_notifications_platform_interface/lib/src/helpers.dart b/flutter_local_notifications_platform_interface/lib/src/helpers.dart index ceed7fdfe..8d91964e4 100644 --- a/flutter_local_notifications_platform_interface/lib/src/helpers.dart +++ b/flutter_local_notifications_platform_interface/lib/src/helpers.dart @@ -7,7 +7,8 @@ void validateId(int id) { throw ArgumentError.value( id, 'id', - 'must fit within the size of a 32-bit integer i.e. in the range [-2^31, 2^31 - 1]', + 'must fit within the size of a 32-bit integer i.e. in the range ' + '[-2^31, 2^31 - 1]', ); // ignore: lines_longer_than_80_chars } } From ae5e48574b3fa97263accb0b2157172d9f2b746e Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Thu, 4 Dec 2025 20:56:59 +1100 Subject: [PATCH 9/9] split applesimutils steps --- .github/workflows/validate.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index c8acd3329..86eafea20 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -328,8 +328,10 @@ jobs: id: simulator-action with: model: 'iPhone 16' - - run: | + - name: Install applesimutils + run: | brew tap wix/brew brew install applesimutils - applesimutils --byId ${{ steps.simulator-action.outputs.udid}} --bundle com.dexterous.flutterLocalNotificationsExample --setPermissions notifications=YES + - name: Grant notification permissions + run: applesimutils --byId ${{ steps.simulator-action.outputs.udid}} --bundle com.dexterous.flutterLocalNotificationsExample --setPermissions notifications=YES - run: melos run test:integration