diff --git a/flutter_local_notifications/CHANGELOG.md b/flutter_local_notifications/CHANGELOG.md index 94d049009..3ee67f74e 100644 --- a/flutter_local_notifications/CHANGELOG.md +++ b/flutter_local_notifications/CHANGELOG.md @@ -1,3 +1,96 @@ +# [1.4.0] + +Please note that there are a number of breaking changes in this release to improve the developer experience when using the plugin APIs. The changes should hopefully be straightforward but please through the changelog carefully just in case. The steps migrate your code has been covered below but the Git history of the example application's `main.dart` file can also be used as reference. + +* [Android] **BREAKING CHANGE** The `style` property of the `AndroidNotificationDetails` class has been removed as it was redundant. No changes are needed unless your application was displaying media notifications (i.e. `style` was set to `AndroidNotificationStyle.Media`). If this is the case, you can migrate your code by setting the `styleInformation` property of the `AndroidNotificationDetails` to an instance of the `MediaNotificationStyleInformation` class. This class is a new addition in this release +* [Android] **BREAKING CHANGE** The `AndroidNotificationSound` abstract class has been introduced to represent Android notification sounds. The `sound` property of the `AndroidNotificationDetails` class has changed from being a `String` type to an `AndroidNotificationSound` type. In this release, the `AndroidNotificationSound` has the following subclasses + + * `RawResourceAndroidNotificationSound`: use this when the sound is raw resource associated with the Android application. Previously, this was the only type of sound supported so applications using the plugin prior to 1.4.0 can migrate their application by using this class. For example, if your previous code was + + ```dart + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'your other channel id', + 'your other channel name', + 'your other channel description', + sound: 'slow_spring_board'); + ``` + + Replace it with + + ```dart + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'your other channel id', + 'your other channel name', + 'your other channel description', + sound: RawResourceAndroidNotificationSound('slow_spring_board'); + ``` + + * `UriAndroidNotificationSound`: use this when a URI refers to the sound on the Android device. This is a new feature being supported as part of this release. Developers may need to write their code to access native Android APIs (e.g. the `RingtoneManager` APIs) to obtain the URIs they need. +* [Android] **BREAKING CHANGE** The `BitmapSource` enum has been replaced by the newly `AndroidBitmap` abstract class and its subclasses. This removes the need to specify the name/path of the bitmap and the source of the bitmap as two separate properties (e.g. the `largeIcon` and `largeIconBitmapSource` properties of the `AndroidNotificationDetails` class). This change affects the following classes + + * `AndroidNotificationDetails`: the `largeIcon` is now an `AndroidBitmap` type instead of a `String` and the `largeIconBitmapSource` property has been removed + * `BigPictureStyleInformation`: the `largeIcon` is now an `AndroidBitmap` type instead of a `String` and the `largeIconBitmapSource` property has been removed. The `bigPicture` is now a `AndroidBitmap` type instead of a `String` and the `bigPictureBitmapSource` property has been removed + + The following describes how each `BitmapSource` value maps to the `AndroidBitmap` subclasses + + * `BitmapSource.Drawable` -> `DrawableResourceAndroidBitmap` + * `BitmapSource.FilePath` -> `FilePathAndroidBitmap` + + Each of these subclasses has a constructor that an argument referring to the bitmap itself. For example, if you previously had the following code + + ```dart + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'your other channel id', + 'your other channel name', + 'your other channel description', + largeIcon: 'sample_large_icon', + largeIconBitmapSource: BitmapSource.Drawable, + ) + ``` + + This would now be replaced with + + ```dart + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'your other channel id', + 'your other channel name', + 'your other channel description', + largeIcon: DrawableResourceAndroidBitmap('sample_large_icon'), + ) + ``` +* [Android] **BREAKING CHANGE** The `IconSource` enum has been replaced by the newly added `AndroidIcon` abstract class and its subclasses. This change was done for similar reasons in replacing the `BitmapSource` enum. This only affects the `Person` class, which is used when displaying each person in a messaging-style notification. Here the `icon` property is now an `AndroidIcon` type instead of a `String` and the `iconSource` property has been removed. + + The following describes how each `IconSource` value maps to the `AndroidIcon` subclasses + + * `IconSource.Drawable` -> `DrawableResourceAndroidIcon` + * `IconSource.FilePath` -> `BitmapFilePathAndroidIcon` + * `IconSource.ContentUri` -> `ContentUriAndroidIcon` + + Each of these subclasses has a constructor that accepts an argument referring to the icon itself. For example, if you previously had the following code + + ```dart + Person( + icon: 'me', + iconSource: IconSource.Drawable, + ) + ``` + + This would now be replaced with + + ```dart + Person( + icon: DrawableResourceAndroidIcon('me'), + ) + ``` + + The `AndroidIcon` also has a `BitmapAssetAndroidIcon` subclass to enables the usage of bitmap icons that have been registered as a Flutter asset via the `pubspec.yaml` file. +* [Android] **BREAKING CHANGE** All properties in the `AndroidNotificationDetails`, `DefaultStyleInformation` and `InboxStyleInformation` classes have been made `final` +* The `DefaultStyleInformation` class now implements the `StyleInformation` class instead of extending it +* Where possible, classes in the plugins have been updated to provide `const` constructors +* Updates to API docs and readme +* Bump Android dependencies +* Fixed a grammar issue 0.9.1 changelog entry + # [1.3.0] * [iOS] **BREAKING CHANGE** Plugin will now throw a `PlatformException` if there was an error returned upon calling the native [`addNotificationRequest`](https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649508-addnotificationrequest) method. Previously the error was logged on the native side the using [`NSLog`](https://developer.apple.com/documentation/foundation/1395275-nslog) function. @@ -122,7 +215,7 @@ # [0.9.1] -* Add support for media notification. This currently only supports showing the specified image as album artwork. Thanks to PR by [gianlucaparadise](https://github.com/gianlucaparadise) +* Added support for media notifications. This currently only supports showing the specified image as album artwork. Thanks to the PR by [gianlucaparadise](https://github.com/gianlucaparadise) # [0.9.0+1] diff --git a/flutter_local_notifications/README.md b/flutter_local_notifications/README.md index 36ad0b01d..5eba8cc0d 100644 --- a/flutter_local_notifications/README.md +++ b/flutter_local_notifications/README.md @@ -40,6 +40,7 @@ A cross platform plugin for displaying local notifications. * [Android] Show progress notifications * [Android] Configure notification visibility on the lockscreen * [iOS] Request notification permissions and customise the permissions being requested around displaying notifications +* [iOS] Display notifications with attachments Note that this plugin aims to provide abstractions for all platforms as opposed to having methods that only work on specific platforms. However, each method allows passing in "platform-specifics" that contains data that is specific for customising notifications on each platform. This approach means that some scenarios may not be covered by the plugin. Developers can either fork or maintain their code for showing notifications in these situations. Note that the plugin still under development so expect the API surface to change over time. @@ -80,13 +81,13 @@ var initializationSettingsIOS = IOSInitializationSettings( var initializationSettings = InitializationSettings( initializationSettingsAndroid, initializationSettingsIOS); await flutterLocalNotificationsPlugin.initialize(initializationSettings, - onSelectNotification: onSelectNotification); + onSelectNotification: selectNotification); ``` -Initialisation should only be done once and the place where this can be done is in the `main` function of the your application. Alternatively, this can be done within the first page shown in your app. Developers should look at the example app, which does the initialisation within the `main` function as the code below is simplified for explaining the concepts. Here we specify we have specified the default icon to use for notifications on Android (refer to the Android Integration section) and designated the function (onSelectNotification) that should fire when a notification has been tapped on. Specifying this callback is entirely optional. In this example, it will trigger navigation to another page and display the payload associated with the notification. +Initialisation should only be done once and the place where this can be done is in the `main` function of the your application. Alternatively, this can be done within the first page shown in your app. Developers can refer to the example app that has code for the initialising within the `main` function. The code above has been simplified for explaining the concepts. Here we have specified the default icon to use for notifications on Android (refer to the Android Integration section) and designated the function (`selectNotification`) that should fire when a notification has been tapped on via the `onSelectNotification` callback. Specifying this callback is entirely optional but here it will trigger navigation to another page and display the payload associated with the notification. ```dart -Future onSelectNotification(String payload) async { +Future selectNotification(String payload) async { if (payload != null) { debugPrint('notification payload: ' + payload); } @@ -99,17 +100,13 @@ Future onSelectNotification(String payload) async { In the real world, this payload could represent the id of the item you want to display the details of. Once the initialisation has been done, then you can manage the displaying of notifications. +On iOS, initialisation may show a prompt to requires users to give the application permission to display notifications (note: permissions don't need to be requested on Android). Depending on when this happens, this may not be the ideal user experience for your application. If so, please refer to the next section on how to work around this. + *Notes around initialisation*: if the app had been launched by tapping on a notification created by this plugin, calling `initialize` is what will trigger the `onSelectNotification` to trigger to handle the notification that the user tapped on. An alternative to handling the "launch notification" is to call the `getNotificationAppLaunchDetails` method that is available in the plugin. This could be used, for example, to change the home route of the app for deep-linking. Calling `initialize` will still cause the `onSelectNotification` callback to fire for the launch notification. It will be up to developers to ensure that they don't process the same notification twice (e.g. by storing and comparing the notification id). ### [iOS only] Requesting notification permissions -By default this plugin will request notification permissions when it is initialised. `IOSInitializationSettings` have three named parameters: -1. `requestSoundPermission`, -1. `requestBadgePermission`, -1. `requestAlertPermission` -that control this behaviour. - -If you want to request permissions at a later point in your application on iOS, set all of the above to false. +The constructor for the `IOSInitializationSettings` class has three named parameters (`requestSoundPermission`, `requestBadgePermission` and `requestAlertPermission`) that controls which permissions are being requested. If you want to request permissions at a later point in your application on iOS, set all of the above to false when initialising the plugin. ```dart FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); @@ -127,7 +124,7 @@ await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification); ``` -Then call `requestPermissions` method with desired permissions at the appropriate point in your application +Then call the `requestPermissions` method with desired permissions at the appropriate point in your application ```dart var result = await flutterLocalNotificationsPlugin @@ -140,7 +137,7 @@ var result = await flutterLocalNotificationsPlugin ); ``` -Here the call to `flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()` returns the iOS implementation of the plugin that contains APIs specific to iOS, provided that the application is running on iOS. The `?.` operator is used here as the result will be null when run on other platforms. Developers may alternative choose to guard this call by checking the platform their application is running on. +Here the call to `flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()` returns the iOS implementation of the plugin that contains APIs specific to iOS if the application is running on iOS. The `?.` operator is used here as the result will be null when run on other platforms. Developers may alternatively choose to guard this call by checking the platform their application is running on. ### Displaying a notification @@ -321,6 +318,18 @@ This should cover the basic functionality. Please check out the `example` direct ## Android integration +### Adding notification icons and sounds + +Notification icons should be added as a drawable resource. The example project/code shows how to set default icon for all notifications and how to specify one for each notification. It is possible to use launcher icon/mipmap and this by default is `@mipmap/ic_launcher` in the Android manifest and can be passed `AndroidInitializationSettings` constructor. However, the offical Android guidance is that you should use drawable resources. Custom notification sounds should be added as a raw resource and the sample illustrates how to play a notification with a custom sound. Refer to the following links around Android resources and notification icons. + + * https://developer.android.com/guide/topics/resources/providing-resources + * https://developer.android.com/studio/write/image-asset-studio#notification + * https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar + +When specifying the large icon bitmap or big picture bitmap (associated with the big picture style), bitmaps can be either a drawable resource or file on the device. This is specified via a single property (e.g. the `largeIcon` property associated with the `AndroidNotificationDetails` class) where a value that is an instance of the `DrawableResourceAndroidBitmap` means the bitmap should be loaded from an drawable resource. If this is an instance of the `FilePathAndroidBitmap`, this indicates it should be loaded from a file referred to by a given file path. + +Note that with Android 8.0+, sounds and vibrations are associated with notification channels and can only be configured when they are first created. Showing/scheduling a notification will create a channel with the specified id if it doesn't exist already. If another notification specifies the same channel id but tries to specify another sound or vibration pattern then nothing occurs. + ### Configuration for scheduled notifications If your application needs the ability to schedule notifications then you need to request permissions to be notified when the phone has been booted as scheduled notifications uses the `AlarmManager` API to determine when notifications should be displayed. However, they are cleared when a phone has been turned off. Requesting permission requires adding the following to the manifest (i.e. your application's `AndroidManifest.xml` file) @@ -353,17 +362,6 @@ If the vibration pattern of an Android notification will be customised then add For reference, the example app's `AndroidManifest.xml` file can be found [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/AndroidManifest.xml) -### Adding notification icons and sounds - -Notification icons should be added as a drawable resource. The example project/code shows how to set default icon for all notifications and how to specify one for each notification. It is possible to use launcher icon/mipmap and this by default is `@mipmap/ic_launcher` in the Android manifest and can be passed `AndroidInitializationSettings` constructor. However, the offical Android guidance is that you should use drawable resources. Custom notification sounds should be added as a raw resource and the sample illustrates how to play a notification with a custom sound. Refer to the following links around Android resources and notification icons. - - * https://developer.android.com/guide/topics/resources/providing-resources - * https://developer.android.com/studio/write/image-asset-studio#notification - * https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar - -When specifying the large icon bitmap or big picture bitmap (associated with the big picture style), bitmaps can be either a drawable resource or file on the device. This is specified via a single property (e.g. the `largeIcon` property associated with the `AndroidNotificationDetails` class) and there will be a corresponding property of the `BitmapSource` enum type (e.g. `largeIconBitmapSource`) that indicates if the string value represents the name of the drawable resource or the path to the bitmap file. - -Note that with Android 8.0+, sounds and vibrations are associated with notification channels and can only be configured when they are first created. Showing/scheduling a notification will create a channel with the specified id if it doesn't exist already. If another notification specifies the same channel id but tries to specify another sound or vibration pattern then nothing occurs. ### Release build configuration @@ -373,12 +371,10 @@ When doing a release build of your app, which is the default setting when buildi -keep class com.dexterous.** { *; } ``` -The plugin also makes use of GSON and the Proguard rules can be found [here](https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg). The example app has a consolidated Proguard rules (`proguard-rules.pro`) file that combines these together for reference [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/proguard-rules.pro). +After doing so, rules specific to the GSON dependency being used by the plugin will also needed to be added. These rules can be found [here](https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg). The example app has a consolidated Proguard rules (`proguard-rules.pro`) file that combines these together for reference [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/proguard-rules.pro). You will also need to ensure that you have configured the resources that should be kept so that resources like your notification icons aren't discarded by the R8 compiler by following the instructions [here](https://developer.android.com/studio/build/shrink-code#keep-resources). Without doing this, you might not see the icon you've specified in your app's notifications. The configuration used by the example app can be found [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/res/raw/keep.xml) where it is specifying that all drawable resources should be kept, as well as the file used to play a custom notification sound (sound file is located [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/res/raw/slow_spring_board.mp3)). -**IMPORTANT**: Starting from version 0.5.0, this library no longer uses the deprecated Android support libraries and has migrated to AndroidX. Developers may require migrating their apps to support this following [this guide](https://developer.android.com/jetpack/androidx/migrate) - ## iOS integration ### General setup diff --git a/flutter_local_notifications/analysis_options.yaml b/flutter_local_notifications/analysis_options.yaml index b45d4fe03..9653b58e1 100644 --- a/flutter_local_notifications/analysis_options.yaml +++ b/flutter_local_notifications/analysis_options.yaml @@ -1 +1,5 @@ -include: package:pedantic/analysis_options.1.8.0.yaml \ No newline at end of file +include: package:pedantic/analysis_options.yaml + +linter: + rules: + - sort_constructors_first \ No newline at end of file diff --git a/flutter_local_notifications/android/build.gradle b/flutter_local_notifications/android/build.gradle index 9a2704bcc..c4935b497 100644 --- a/flutter_local_notifications/android/build.gradle +++ b/flutter_local_notifications/android/build.gradle @@ -34,7 +34,7 @@ android { } dependencies { - implementation "androidx.core:core:1.1.0" + implementation "androidx.core:core:1.2.0" implementation "androidx.media:media:1.1.0" implementation "com.google.code.gson:gson:2.8.5" } diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/BitmapSource.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/BitmapSource.java index e7876c22c..8b94919e9 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/BitmapSource.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/BitmapSource.java @@ -1,6 +1,6 @@ package com.dexterous.flutterlocalnotifications; public enum BitmapSource { - Drawable, + DrawableResource, FilePath } diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java index 416ab6f45..63bbc6641 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java @@ -336,7 +336,7 @@ private static int getDrawableResourceId(Context context, String name) { private static Bitmap getBitmapFromSource(Context context, String bitmapPath, BitmapSource bitmapSource) { Bitmap bitmap = null; - if (bitmapSource == BitmapSource.Drawable) { + if (bitmapSource == BitmapSource.DrawableResource) { bitmap = BitmapFactory.decodeResource(context.getResources(), getDrawableResourceId(context, bitmapPath)); } else if (bitmapSource == BitmapSource.FilePath) { bitmap = BitmapFactory.decodeFile(bitmapPath); @@ -348,7 +348,7 @@ private static Bitmap getBitmapFromSource(Context context, String bitmapPath, Bi private static IconCompat getIconFromSource(Context context, String iconPath, IconSource iconSource) { IconCompat icon = null; switch (iconSource) { - case Drawable: + case DrawableResource: icon = IconCompat.createWithResource(context, getDrawableResourceId(context, iconPath)); break; case BitmapFilePath: @@ -357,7 +357,7 @@ private static IconCompat getIconFromSource(Context context, String iconPath, Ic case ContentUri: icon = IconCompat.createWithContentUri(iconPath); break; - case BitmapAsset: + case FlutterBitmapAsset: try { AssetFileDescriptor assetFileDescriptor = context.getAssets().openFd(FlutterMain.getLookupKeyForAsset(iconPath)); FileInputStream fileInputStream = assetFileDescriptor.createInputStream(); @@ -879,13 +879,13 @@ private boolean hasInvalidBigPictureResources(Result result, NotificationDetails BigPictureStyleInformation bigPictureStyleInformation = (BigPictureStyleInformation) notificationDetails.styleInformation; if (hasInvalidLargeIcon(result, bigPictureStyleInformation.largeIcon, bigPictureStyleInformation.largeIconBitmapSource)) return true; - return bigPictureStyleInformation.bigPictureBitmapSource == BitmapSource.Drawable && !isValidDrawableResource(applicationContext, bigPictureStyleInformation.bigPicture, result, INVALID_BIG_PICTURE_ERROR_CODE); + return bigPictureStyleInformation.bigPictureBitmapSource == BitmapSource.DrawableResource && !isValidDrawableResource(applicationContext, bigPictureStyleInformation.bigPicture, result, INVALID_BIG_PICTURE_ERROR_CODE); } return false; } private boolean hasInvalidLargeIcon(Result result, String largeIcon, BitmapSource largeIconBitmapSource) { - return !StringUtils.isNullOrEmpty(largeIcon) && largeIconBitmapSource == BitmapSource.Drawable && !isValidDrawableResource(applicationContext, largeIcon, result, INVALID_LARGE_ICON_ERROR_CODE); + return !StringUtils.isNullOrEmpty(largeIcon) && largeIconBitmapSource == BitmapSource.DrawableResource && !isValidDrawableResource(applicationContext, largeIcon, result, INVALID_LARGE_ICON_ERROR_CODE); } private boolean hasInvalidIcon(Result result, String icon) { diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/IconSource.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/IconSource.java index d0effea66..0186686f9 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/IconSource.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/models/IconSource.java @@ -1,8 +1,8 @@ package com.dexterous.flutterlocalnotifications.models; public enum IconSource { - Drawable, + DrawableResource, BitmapFilePath, ContentUri, - BitmapAsset + FlutterBitmapAsset } diff --git a/flutter_local_notifications/example/android/app/build.gradle b/flutter_local_notifications/example/android/app/build.gradle index a708dfb90..9fe71508c 100644 --- a/flutter_local_notifications/example/android/app/build.gradle +++ b/flutter_local_notifications/example/android/app/build.gradle @@ -63,5 +63,5 @@ dependencies { androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation "androidx.core:core:1.1.0" + implementation "androidx.core:core:1.2.0" } diff --git a/flutter_local_notifications/example/lib/main.dart b/flutter_local_notifications/example/lib/main.dart index 22d83d876..0d24dc91a 100644 --- a/flutter_local_notifications/example/lib/main.dart +++ b/flutter_local_notifications/example/lib/main.dart @@ -588,6 +588,7 @@ class _HomePageState extends State { 'media channel name', 'media channel description', largeIcon: FilePathAndroidBitmap(largeIconPath), + styleInformation: MediaStyleInformation(), ); var platformChannelSpecifics = NotificationDetails(androidPlatformChannelSpecifics, null); @@ -649,7 +650,7 @@ class _HomePageState extends State { name: 'Coworker', key: '2', uri: 'tel:9876543210', - icon: BitmapAssetAndroidIcon('icons/coworker.png'), + icon: FlutterBitmapAssetAndroidIcon('icons/coworker.png'), ); // download the icon that would be use for the lunch bot person var largeIconPath = await _downloadAndSaveFile( diff --git a/flutter_local_notifications/lib/flutter_local_notifications.dart b/flutter_local_notifications/lib/flutter_local_notifications.dart index 074f67fe5..d2081df89 100644 --- a/flutter_local_notifications/lib/flutter_local_notifications.dart +++ b/flutter_local_notifications/lib/flutter_local_notifications.dart @@ -9,6 +9,7 @@ export 'src/platform_specifics/android/styles/default_style_information.dart'; export 'src/platform_specifics/android/styles/big_text_style_information.dart'; export 'src/platform_specifics/android/styles/big_picture_style_information.dart'; export 'src/platform_specifics/android/styles/inbox_style_information.dart'; +export 'src/platform_specifics/android/styles/media_style_information.dart'; export 'src/platform_specifics/android/styles/messaging_style_information.dart'; export 'src/platform_specifics/android/bitmap.dart'; export 'src/platform_specifics/android/enums.dart' 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 85760c2ee..9ecfdbd60 100644 --- a/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart +++ b/flutter_local_notifications/lib/src/flutter_local_notifications_plugin.dart @@ -48,7 +48,7 @@ class FlutterLocalNotificationsPlugin { final Platform _platform; /// Returns the underlying platform-specific implementation of given type [T], which - /// must be the type of a concrete [FlutterLocalNotificationsPlatform](https://pub.dev/documentation/flutter_local_notifications_platform_interface/latest/flutter_local_notifications_platform_interface/FlutterLocalNotificationsPlatform-class.html) subclass. + /// must be a concrete subclass of [FlutterLocalNotificationsPlatform](https://pub.dev/documentation/flutter_local_notifications_platform_interface/latest/flutter_local_notifications_platform_interface/FlutterLocalNotificationsPlatform-class.html). /// /// Requires running on the appropriate platform that matches the specified type for a result to be returned. /// For example, when the specified type argument is of type [AndroidFlutterLocalNotificationsPlugin], diff --git a/flutter_local_notifications/lib/src/initialization_settings.dart b/flutter_local_notifications/lib/src/initialization_settings.dart index 7188a965c..96e16705d 100644 --- a/flutter_local_notifications/lib/src/initialization_settings.dart +++ b/flutter_local_notifications/lib/src/initialization_settings.dart @@ -3,11 +3,14 @@ import 'platform_specifics/ios/initialization_settings.dart'; /// Settings for initializing the plugin for each platform class InitializationSettings { + const InitializationSettings( + this.android, + this.ios, + ); + /// Settings for Android final AndroidInitializationSettings android; /// Settings for iOS final IOSInitializationSettings ios; - - const InitializationSettings(this.android, this.ios); } diff --git a/flutter_local_notifications/lib/src/notification_details.dart b/flutter_local_notifications/lib/src/notification_details.dart index 4e5c09c65..3ce9e297a 100644 --- a/flutter_local_notifications/lib/src/notification_details.dart +++ b/flutter_local_notifications/lib/src/notification_details.dart @@ -3,11 +3,14 @@ import 'platform_specifics/android/notification_details.dart'; /// Contains notification settings for each platform class NotificationDetails { + const NotificationDetails( + this.android, + this.iOS, + ); + /// Notification details for Android final AndroidNotificationDetails android; /// Notification details for iOS final IOSNotificationDetails iOS; - - const NotificationDetails(this.android, this.iOS); } diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/bitmap.dart b/flutter_local_notifications/lib/src/platform_specifics/android/bitmap.dart index f4d198249..d10bc88c6 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/bitmap.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/bitmap.dart @@ -5,8 +5,8 @@ abstract class AndroidBitmap { } /// Represents a drawable resource belonging to the Android application that should be used as a bitmap on Android. -class DrawableResourceAndroidBitmap extends AndroidBitmap { - DrawableResourceAndroidBitmap(this._bitmap); +class DrawableResourceAndroidBitmap implements AndroidBitmap { + const DrawableResourceAndroidBitmap(this._bitmap); final String _bitmap; @@ -18,8 +18,8 @@ class DrawableResourceAndroidBitmap extends AndroidBitmap { } /// Represents a file path that should be used for a bitmap on Android. -class FilePathAndroidBitmap extends AndroidBitmap { - FilePathAndroidBitmap(this._bitmap); +class FilePathAndroidBitmap implements AndroidBitmap { + const FilePathAndroidBitmap(this._bitmap); final String _bitmap; 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 b9121d557..6c3d4bcbe 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/enums.dart @@ -6,7 +6,7 @@ enum AndroidIconSource { DrawableResource, BitmapFilePath, ContentUri, - BitmapAsset + FlutterBitmapAsset } /// The available notification styles on Android. @@ -34,6 +34,8 @@ enum AndroidNotificationChannelAction { CreateIfNotExists, Update } /// /// Required for Android 8.0+ class Importance { + const Importance(this.value); + static const Unspecified = Importance(-1000); static const None = Importance(0); static const Min = Importance(1); @@ -47,12 +49,12 @@ class Importance { [Unspecified, None, Min, Low, Default, High, Max]; final int value; - - const Importance(this.value); } /// Priority for notifications on Android 7.1 and lower. class Priority { + const Priority(this.value); + static const Min = Priority(-2); static const Low = Priority(-1); static const Default = Priority(0); @@ -63,8 +65,6 @@ class Priority { static List get values => [Min, Low, Default, High, Max]; final int value; - - const Priority(this.value); } /// The available alert behaviours for grouped notifications. diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/icon.dart b/flutter_local_notifications/lib/src/platform_specifics/android/icon.dart index 99198578b..fc42dfc4c 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/icon.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/icon.dart @@ -5,8 +5,8 @@ abstract class AndroidIcon { } /// Represents a drawable resource belonging to the Android application that should be used as an icon on Android. -class DrawableResourceAndroidIcon extends AndroidIcon { - DrawableResourceAndroidIcon(this._icon); +class DrawableResourceAndroidIcon implements AndroidIcon { + const DrawableResourceAndroidIcon(this._icon); final String _icon; @@ -18,8 +18,8 @@ class DrawableResourceAndroidIcon extends AndroidIcon { } /// Represents a file path to a bitmap that should be used for as an icon on Android. -class BitmapFilePathAndroidIcon extends AndroidIcon { - BitmapFilePathAndroidIcon(this._icon); +class BitmapFilePathAndroidIcon implements AndroidIcon { + const BitmapFilePathAndroidIcon(this._icon); final String _icon; @@ -29,8 +29,8 @@ class BitmapFilePathAndroidIcon extends AndroidIcon { } /// Represents a content URI that should be used for as an icon on Android. -class ContentUriAndroidIcon extends AndroidIcon { - ContentUriAndroidIcon(this._icon); +class ContentUriAndroidIcon implements AndroidIcon { + const ContentUriAndroidIcon(this._icon); final String _icon; @@ -40,8 +40,8 @@ class ContentUriAndroidIcon extends AndroidIcon { } /// Represents a bitmap asset belonging to the Flutter application that should be used for as an icon on Android. -class BitmapAssetAndroidIcon extends AndroidIcon { - BitmapAssetAndroidIcon(this._icon); +class FlutterBitmapAssetAndroidIcon implements AndroidIcon { + const FlutterBitmapAssetAndroidIcon(this._icon); final String _icon; diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/initialization_settings.dart b/flutter_local_notifications/lib/src/platform_specifics/android/initialization_settings.dart index e8c0e556c..2aa6eab1a 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/initialization_settings.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/initialization_settings.dart @@ -1,11 +1,11 @@ /// Plugin initialization settings for Android. class AndroidInitializationSettings { + const AndroidInitializationSettings(this.defaultIcon); + /// Sets the default icon for notifications. final String defaultIcon; - const AndroidInitializationSettings(this.defaultIcon); - - /// Create a [Map] object that describes the [AndroidInitializationSettings] object. + /// Creates a [Map] object that describes the [AndroidInitializationSettings] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { 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 98e22365e..5d0412091 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/message.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/message.dart @@ -2,6 +2,18 @@ import 'person.dart'; /// Represents a message used in Android messaging style notifications. class Message { + const Message( + this.text, + this.timestamp, + this.person, { + this.dataMimeType, + this.dataUri, + }) : assert(timestamp != null, 'timestamp must be provided'), + assert( + (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; @@ -11,6 +23,9 @@ class Message { final DateTime timestamp; /// Person that sent this message. + /// + /// When this is set to `null` the `Person` given to [MessagingStyleInformation.person] + /// i.e. this would indicate that the message was sent from the user. final Person person; /// MIME type for this message context when the [dataUri] is provided. @@ -21,21 +36,7 @@ class Message { /// The original text will be used if the content or MIME type isn't supported final String dataUri; - Message( - this.text, - this.timestamp, - this.person, { - this.dataMimeType, - this.dataUri, - }) { - assert(timestamp != null, 'timestamp must be provided'); - assert( - (dataMimeType == null && dataUri == null) || - (dataMimeType != null && dataUri != null), - 'Must provide both dataMimeType and dataUri together or not at all.'); - } - - /// Create a [Map] object that describes the [Message] object. + /// Creates a [Map] object that describes the [Message] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart b/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart index ddce31509..75ef755c5 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/notification_details.dart @@ -14,9 +14,46 @@ import 'styles/default_style_information.dart'; /// Configures the notification on Android. class AndroidNotificationDetails { + const AndroidNotificationDetails( + this.channelId, + this.channelName, + this.channelDescription, { + this.icon, + this.importance = Importance.Default, + this.priority = Priority.Default, + this.styleInformation, + this.playSound = true, + this.sound, + this.enableVibration = true, + this.vibrationPattern, + this.groupKey, + this.setAsGroupSummary, + this.groupAlertBehavior = GroupAlertBehavior.All, + this.autoCancel = true, + this.ongoing, + this.color, + this.largeIcon, + this.onlyAlertOnce, + this.showWhen = true, + this.channelShowBadge = true, + this.showProgress = false, + this.maxProgress = 0, + this.progress = 0, + this.indeterminate = false, + this.channelAction = AndroidNotificationChannelAction.CreateIfNotExists, + this.enableLights = false, + this.ledColor, + this.ledOnMs, + this.ledOffMs, + this.ticker, + this.visibility, + this.timeoutAfter, + this.category, + }); + /// The icon that should be used when displaying the notification. /// - /// When not specified, this will use the default icon that has been configured. + /// When this is set to `null`, the default icon given to [AndroidInitializationSettings.defaultIcon] will be used. final String icon; /// The channel's id. @@ -152,44 +189,7 @@ class AndroidNotificationDetails { /// Refer to Android notification API documentation at https://developer.android.com/reference/androidx/core/app/NotificationCompat.html#constants_2 for the available categories final String category; - AndroidNotificationDetails( - this.channelId, - this.channelName, - this.channelDescription, { - this.icon, - this.importance = Importance.Default, - this.priority = Priority.Default, - this.styleInformation, - this.playSound = true, - this.sound, - this.enableVibration = true, - this.vibrationPattern, - this.groupKey, - this.setAsGroupSummary, - this.groupAlertBehavior = GroupAlertBehavior.All, - this.autoCancel = true, - this.ongoing, - this.color, - this.largeIcon, - this.onlyAlertOnce, - this.showWhen = true, - this.channelShowBadge = true, - this.showProgress = false, - this.maxProgress = 0, - this.progress = 0, - this.indeterminate = false, - this.channelAction = AndroidNotificationChannelAction.CreateIfNotExists, - this.enableLights = false, - this.ledColor, - this.ledOnMs, - this.ledOffMs, - this.ticker, - this.visibility, - this.timeoutAfter, - this.category, - }); - - /// Create a [Map] object that describes the [AndroidNotificationDetails] object. + /// Creates a [Map] object that describes the [AndroidNotificationDetails] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/notification_sound.dart b/flutter_local_notifications/lib/src/platform_specifics/android/notification_sound.dart index 29d84cbb2..c7b8238a2 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/notification_sound.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/notification_sound.dart @@ -8,7 +8,7 @@ abstract class AndroidNotificationSound { /// /// These resources would be found in the `res/raw` directory of the Android application class RawResourceAndroidNotificationSound implements AndroidNotificationSound { - RawResourceAndroidNotificationSound(this._sound); + const RawResourceAndroidNotificationSound(this._sound); final String _sound; @@ -22,7 +22,7 @@ class RawResourceAndroidNotificationSound implements AndroidNotificationSound { /// One way of obtaining such URIs is to use the native Android RingtoneManager APIs, /// which may require developers to write their own to access the API. class UriAndroidNotificationSound implements AndroidNotificationSound { - UriAndroidNotificationSound(this._sound); + const UriAndroidNotificationSound(this._sound); final String _sound; diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/person.dart b/flutter_local_notifications/lib/src/platform_specifics/android/person.dart index 11a5d6b6b..e77acabf9 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/person.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/person.dart @@ -4,6 +4,15 @@ import 'enums.dart'; /// Details of a person e.g. someone who sent a message. class Person { + const Person({ + this.bot, + this.icon, + this.important, + this.key, + this.name, + this.uri, + }); + /// Whether or not this person represents a machine rather than a human. final bool bot; @@ -22,15 +31,6 @@ class Person { /// Uri for this person. final String uri; - Person({ - this.bot, - this.icon, - this.important, - this.key, - this.name, - this.uri, - }); - /// Creates a [Map] object that describes the [Person] object. /// /// Mainly for internal use to send the data over a platform channel. @@ -60,10 +60,10 @@ class Person { 'icon': icon.icon, 'iconSource': AndroidIconSource.ContentUri.index, }; - } else if (icon is BitmapAssetAndroidIcon) { + } else if (icon is FlutterBitmapAssetAndroidIcon) { return { 'icon': icon.icon, - 'iconSource': AndroidIconSource.BitmapAsset.index, + 'iconSource': AndroidIconSource.FlutterBitmapAsset.index, }; } else { return {}; diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_picture_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_picture_style_information.dart index dc9a98d69..3086c8c6d 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_picture_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_picture_style_information.dart @@ -5,6 +5,18 @@ import '../enums.dart'; /// Used to pass the content for an Android notification displayed using the big picture style. class BigPictureStyleInformation extends DefaultStyleInformation { + const BigPictureStyleInformation( + this.bigPicture, { + this.contentTitle, + this.summaryText, + this.htmlFormatContentTitle = false, + this.htmlFormatSummaryText = false, + this.largeIcon, + bool htmlFormatContent = false, + bool htmlFormatTitle = false, + this.hideExpandedLargeIcon = false, + }) : super(htmlFormatContent, htmlFormatTitle); + /// Overrides ContentTitle in the big form of the template. final String contentTitle; @@ -26,17 +38,6 @@ class BigPictureStyleInformation extends DefaultStyleInformation { /// Hides the large icon when showing the expanded notification. final bool hideExpandedLargeIcon; - BigPictureStyleInformation(this.bigPicture, - {this.contentTitle, - this.summaryText, - this.htmlFormatContentTitle = false, - this.htmlFormatSummaryText = false, - this.largeIcon, - bool htmlFormatContent = false, - bool htmlFormatTitle = false, - this.hideExpandedLargeIcon = false}) - : super(htmlFormatContent, htmlFormatTitle); - /// Creates a [Map] object that describes the [BigPictureStyleInformation] object. /// /// Mainly for internal use to send the data over a platform channel. diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_text_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_text_style_information.dart index 499c48ecf..0eb449fdd 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_text_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/big_text_style_information.dart @@ -2,6 +2,17 @@ import 'default_style_information.dart'; /// Used to pass the content for an Android notification displayed using the big text style. class BigTextStyleInformation extends DefaultStyleInformation { + const BigTextStyleInformation( + this.bigText, { + this.htmlFormatBigText = false, + this.contentTitle, + this.htmlFormatContentTitle = false, + this.summaryText, + this.htmlFormatSummaryText = false, + bool htmlFormatContent = false, + bool htmlFormatTitle = false, + }) : super(htmlFormatContent, htmlFormatTitle); + /// Provide the longer text to be displayed in the big form of the template in place of the content text. final String bigText; @@ -20,17 +31,7 @@ class BigTextStyleInformation extends DefaultStyleInformation { /// Specifies if formatting should be applied to the first line of text after the detail section in the big form of the template. final bool htmlFormatSummaryText; - BigTextStyleInformation(this.bigText, - {this.htmlFormatBigText = false, - this.contentTitle, - this.htmlFormatContentTitle = false, - this.summaryText, - this.htmlFormatSummaryText = false, - bool htmlFormatContent = false, - bool htmlFormatTitle = false}) - : super(htmlFormatContent, htmlFormatTitle); - - /// Create a [Map] object that describes the [BigTextStyleInformation] object. + /// Creates a [Map] object that describes the [BigTextStyleInformation] object. /// /// Mainly for internal use to send the data over a platform channel. @override 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 f5ea198c9..3f9c33514 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 @@ -1,16 +1,19 @@ import 'style_information.dart'; /// The default Android notification style. -class DefaultStyleInformation extends StyleInformation { +class DefaultStyleInformation implements StyleInformation { + const DefaultStyleInformation( + this.htmlFormatContent, + this.htmlFormatTitle, + ); + /// Specifies if formatting should be applied to the content through HTML markup. final bool htmlFormatContent; /// Specifies if formatting should be applied to the title through HTML markup. final bool htmlFormatTitle; - DefaultStyleInformation(this.htmlFormatContent, this.htmlFormatTitle); - - /// Create a [Map] object that describes the [DefaultStyleInformation] object. + /// Creates a [Map] object that describes the [DefaultStyleInformation] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/inbox_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/inbox_style_information.dart index 958695679..d49a2a5cf 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/inbox_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/inbox_style_information.dart @@ -2,6 +2,17 @@ import 'default_style_information.dart'; /// Used to pass the content for an Android notification displayed using the inbox style. class InboxStyleInformation extends DefaultStyleInformation { + const InboxStyleInformation( + this.lines, { + this.htmlFormatLines = false, + this.contentTitle, + this.htmlFormatContentTitle = false, + this.summaryText, + this.htmlFormatSummaryText = false, + bool htmlFormatContent = false, + bool htmlFormatTitle = false, + }) : super(htmlFormatContent, htmlFormatTitle); + /// Overrides ContentTitle in the big form of the template. final String contentTitle; @@ -20,18 +31,7 @@ class InboxStyleInformation extends DefaultStyleInformation { /// Specifies if formatting should be applied to the first line of text after the detail section in the big form of the template. final bool htmlFormatSummaryText; - InboxStyleInformation( - this.lines, { - this.htmlFormatLines = false, - this.contentTitle, - this.htmlFormatContentTitle = false, - this.summaryText, - this.htmlFormatSummaryText = false, - bool htmlFormatContent = false, - bool htmlFormatTitle = false, - }) : super(htmlFormatContent, htmlFormatTitle); - - /// Create a [Map] object that describes the [InboxStyleInformation] object. + /// Creates a [Map] object that describes the [InboxStyleInformation] object. /// /// Mainly for internal use to send the data over a platform channel. @override diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/media_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/media_style_information.dart index cfea79c3a..52386a96e 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/media_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/media_style_information.dart @@ -2,11 +2,9 @@ import 'default_style_information.dart'; /// Used to pass the content for an Android notification displayed using the media style. /// -/// When used, the bitmap specified [largeIcon](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/AndroidNotificationDetails/largeIcon.html) -/// as part of the [AndroidNotificationDetails](https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/AndroidNotificationDetails-class.html) -/// class will be treated as album artwork. +/// When used, the bitmap given to [AndroidNotificationDetails.largeIcon] will be treated as album artwork. class MediaStyleInformation extends DefaultStyleInformation { - MediaStyleInformation({ + const MediaStyleInformation({ bool htmlFormatContent = false, bool htmlFormatTitle = false, }) : super(htmlFormatContent, htmlFormatTitle); diff --git a/flutter_local_notifications/lib/src/platform_specifics/android/styles/messaging_style_information.dart b/flutter_local_notifications/lib/src/platform_specifics/android/styles/messaging_style_information.dart index fd00cb14c..7b4ef81aa 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/android/styles/messaging_style_information.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/android/styles/messaging_style_information.dart @@ -4,6 +4,17 @@ import '../message.dart'; /// Used to pass the content for an Android notification displayed using the messaging style. class MessagingStyleInformation extends DefaultStyleInformation { + MessagingStyleInformation( + this.person, { + this.conversationTitle, + this.groupConversation, + this.messages, + bool htmlFormatContent = false, + bool htmlFormatTitle = false, + }) : super(htmlFormatContent, htmlFormatTitle) { + assert(this.person?.name != null, 'Must provide the details of the person'); + } + /// The person displayed for any messages that are sent by the user. final Person person; @@ -16,18 +27,7 @@ class MessagingStyleInformation extends DefaultStyleInformation { /// Messages to be displayed by this notification final List messages; - MessagingStyleInformation( - this.person, { - this.conversationTitle, - this.groupConversation, - this.messages, - bool htmlFormatContent = false, - bool htmlFormatTitle = false, - }) : super(htmlFormatContent, htmlFormatTitle) { - assert(this.person?.name != null, 'Must provide the details of the person'); - } - - /// Create a [Map] object that describes the [MessagingStyleInformation] object. + /// Creates a [Map] object that describes the [MessagingStyleInformation] object. /// /// Mainly for internal use to send the data over a platform channel. @override diff --git a/flutter_local_notifications/lib/src/platform_specifics/ios/initialization_settings.dart b/flutter_local_notifications/lib/src/platform_specifics/ios/initialization_settings.dart index 0efc882e4..db4e66ac0 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/ios/initialization_settings.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/ios/initialization_settings.dart @@ -2,6 +2,16 @@ import '../../typedefs.dart'; /// Plugin initialization settings for iOS. class IOSInitializationSettings { + const IOSInitializationSettings({ + this.requestAlertPermission = true, + this.requestSoundPermission = true, + this.requestBadgePermission = true, + this.defaultPresentAlert = true, + this.defaultPresentSound = true, + this.defaultPresentBadge = true, + this.onDidReceiveLocalNotification, + }); + /// Request permission to display an alert. /// /// Default value is true. @@ -41,17 +51,7 @@ class IOSInitializationSettings { /// Applicable to iOS versions below 10. final DidReceiveLocalNotificationCallback onDidReceiveLocalNotification; - const IOSInitializationSettings({ - this.requestAlertPermission = true, - this.requestSoundPermission = true, - this.requestBadgePermission = true, - this.defaultPresentAlert = true, - this.defaultPresentSound = true, - this.defaultPresentBadge = true, - this.onDidReceiveLocalNotification, - }); - - /// Create a [Map] object that describes the [IOSInitializationSettings] object. + /// Creates a [Map] object that describes the [IOSInitializationSettings] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/platform_specifics/ios/notification_attachment.dart b/flutter_local_notifications/lib/src/platform_specifics/ios/notification_attachment.dart index f5f5d2eda..ea8d95e95 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/ios/notification_attachment.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/ios/notification_attachment.dart @@ -1,5 +1,10 @@ /// Represents an attachment for an iOS notification. class IOSNotificationAttachment { + const IOSNotificationAttachment( + this.filePath, { + this.identifier, + }) : assert(filePath != null); + /// The local file path to the attachment. /// /// See the documentation at https://developer.apple.com/documentation/usernotifications/unnotificationattachment?language=objc @@ -11,12 +16,7 @@ class IOSNotificationAttachment { /// When left empty, the iOS APIs will generate a unique identifier final String identifier; - const IOSNotificationAttachment( - this.filePath, { - this.identifier, - }) : assert(filePath != null); - - /// Create a [Map] object that describes the [IOSNotificationAttachment] object. + /// Creates a [Map] object that describes the [IOSNotificationAttachment] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/platform_specifics/ios/notification_details.dart b/flutter_local_notifications/lib/src/platform_specifics/ios/notification_details.dart index 0725f2758..392982341 100644 --- a/flutter_local_notifications/lib/src/platform_specifics/ios/notification_details.dart +++ b/flutter_local_notifications/lib/src/platform_specifics/ios/notification_details.dart @@ -2,18 +2,30 @@ import 'notification_attachment.dart'; /// Configures the notification details on iOS. class IOSNotificationDetails { + const IOSNotificationDetails({ + this.presentAlert, + this.presentBadge, + this.presentSound, + this.sound, + this.badgeNumber, + this.attachments, + }); + /// Display an alert when the notification is triggered while app is in the foreground. /// + /// When this is set to `null`, it will use the default setting given to [IOSInitializationSettings.defaultPresentAlert]. /// Applicable to iOS 10 and above. final bool presentAlert; /// Play a sound when the notification is triggered while app is in the foreground. /// + /// When this is set to `null`, it will use the default setting given to [IOSInitializationSettings.defaultPresentSound]. /// Applicable to iOS 10 and above. final bool presentSound; /// Apply the badge value when the notification is triggered while app is in the foreground. /// + /// When this is set to `null`, it will use the default setting given to [IOSInitializationSettings.defaultPresentBadge]. /// Applicable to iOS 10 and above. final bool presentBadge; @@ -24,8 +36,8 @@ class IOSNotificationDetails { /// Specify the number to display as the app icon's badge when the notification arrives. /// - /// Specify the number 0 to remove the current badge, if present. Greater than 0 to display a badge with that number. - /// Specify null to leave the current badge unchanged. + /// Specify the number `0` to remove the current badge, if present. Greater than `0` to display a badge with that number. + /// Specify `null` to leave the current badge unchanged. final int badgeNumber; /// Specifies the list of attachments included with the notification. @@ -33,16 +45,7 @@ class IOSNotificationDetails { /// Applicable to iOS 10 and above. final List attachments; - IOSNotificationDetails({ - this.presentAlert, - this.presentBadge, - this.presentSound, - this.sound, - this.badgeNumber, - this.attachments, - }); - - /// Create a [Map] object that describes the [IOSNotificationDetails] object. + /// Creates a [Map] object that describes the [IOSNotificationDetails] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/lib/src/types.dart b/flutter_local_notifications/lib/src/types.dart index c3e673c99..cfbed0e6c 100644 --- a/flutter_local_notifications/lib/src/types.dart +++ b/flutter_local_notifications/lib/src/types.dart @@ -1,5 +1,7 @@ /// The days of the week. class Day { + const Day(this.value); + static const Sunday = Day(1); static const Monday = Day(2); static const Tuesday = Day(3); @@ -13,12 +15,18 @@ class Day { [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]; final int value; - - const Day(this.value); } /// Used for specifying a time in 24 hour format. class Time { + const Time([ + this.hour = 0, + this.minute = 0, + this.second = 0, + ]) : assert(hour >= 0 && hour < 24), + assert(minute >= 0 && minute < 60), + assert(second >= 0 && second < 60); + /// The hour component of the time. /// /// Accepted range is 0 to 23 inclusive. @@ -34,13 +42,7 @@ class Time { /// Accepted range is 0 to 59 inclusive. final int second; - Time([this.hour = 0, this.minute = 0, this.second = 0]) { - assert(this.hour >= 0 && this.hour < 24); - assert(this.minute >= 0 && this.minute < 60); - assert(this.second >= 0 && this.second < 60); - } - - /// Create a [Map] object that describes the [Time] object. + /// Creates a [Map] object that describes the [Time] object. /// /// Mainly for internal use to send the data over a platform channel. Map toMap() { diff --git a/flutter_local_notifications/pubspec.yaml b/flutter_local_notifications/pubspec.yaml index 28b682b0c..0e909ca4d 100644 --- a/flutter_local_notifications/pubspec.yaml +++ b/flutter_local_notifications/pubspec.yaml @@ -1,6 +1,6 @@ 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: 1.3.0 +version: 1.4.0 homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications dependencies: