/
notification_details.dart
407 lines (344 loc) · 14.8 KB
/
notification_details.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import 'dart:typed_data';
import 'dart:ui';
import 'bitmap.dart';
import 'categories.dart';
import 'enums.dart';
import 'notification_sound.dart';
import 'styles/style_information.dart';
/// Mirrors the `RemoteInput` functionality available in NotificationCompat.
///
/// See the official docs at
/// https://developer.android.com/reference/kotlin/androidx/core/app/RemoteInput?hl=en
/// for details.
class AndroidNotificationActionInput {
/// Constructs a [AndroidNotificationActionInput]. The platform will create
/// this object using `RemoteInput.Builder`. See the official docs
/// https://developer.android.com/reference/kotlin/androidx/core/app/RemoteInput.Builder?hl=en
/// for details.
const AndroidNotificationActionInput({
this.choices = const <String>[],
this.allowFreeFormInput = true,
this.label,
this.allowedMimeTypes = const <String>{},
});
/// Specifies choices available to the user to satisfy this input.
final List<String> choices;
/// Specifies whether the user can provide arbitrary text values.
final bool allowFreeFormInput;
/// Set a label to be displayed to the user when collecting this input.
final String? label;
/// Specifies whether the user can provide arbitrary values.
final Set<String> allowedMimeTypes;
}
/// Mirrors the `Action` class in AndroidX.
///
/// See the offical docs at
/// https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Action?hl=en
/// for details.
class AndroidNotificationAction {
/// Constructs a [AndroidNotificationAction] object. The platform will create
/// this object using `Action.Builder`. See the offical docs
/// https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Action.Builder?hl=en
/// for details.
const AndroidNotificationAction(
this.id,
this.title, {
this.titleColor,
this.icon,
this.contextual = false,
this.showsUserInterface = false,
this.allowGeneratedReplies = false,
this.inputs = const <AndroidNotificationActionInput>[],
this.cancelNotification = true,
});
/// This ID will be sent back in the action handler defined in
/// [FlutterLocalNotificationsPlugin].
final String id;
/// The title of the action
final String title;
/// The color of the title of the action
final Color? titleColor;
/// Icon to show for this action.
final AndroidBitmap<Object>? icon;
/// Sets whether this Action is a contextual action, i.e. whether the action
/// is dependent on the notification message body. An example of a contextual
/// action could be an action opening a map application with an address shown
/// in the notification.
final bool contextual;
/// Set whether or not this Action's PendingIntent will open a user interface.
final bool showsUserInterface;
/// Set whether the platform should automatically generate possible replies to
/// add to RemoteInput#getChoices(). If the Action doesn't have a RemoteInput,
/// this has no effect.
///
/// You need to specify [inputs] for this property to work.
final bool allowGeneratedReplies;
/// Add an input to be collected from the user when this action is sent.
final List<AndroidNotificationActionInput> inputs;
/// Set whether the notification should be canceled when this action is
/// selected.
final bool cancelNotification;
}
/// Contains notification details specific to Android.
class AndroidNotificationDetails {
/// Constructs an instance of [AndroidNotificationDetails].
const AndroidNotificationDetails(
this.channelId,
this.channelName, {
this.channelDescription,
this.icon,
this.importance = Importance.defaultImportance,
this.priority = Priority.defaultPriority,
this.styleInformation,
this.playSound = true,
this.sound,
this.enableVibration = true,
this.vibrationPattern,
this.groupKey,
this.setAsGroupSummary = false,
this.groupAlertBehavior = GroupAlertBehavior.all,
this.autoCancel = true,
this.ongoing = false,
this.color,
this.largeIcon,
this.onlyAlertOnce = false,
this.showWhen = true,
this.when,
this.usesChronometer = false,
this.chronometerCountDown = false,
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,
this.fullScreenIntent = false,
this.shortcutId,
this.additionalFlags,
this.subText,
this.tag,
this.actions,
this.colorized = false,
this.number,
this.audioAttributesUsage = AudioAttributesUsage.notification,
});
/// The icon that should be used when displaying the notification.
///
/// When this is set to `null`, the default icon given to
/// [AndroidInitializationSettings.defaultIcon] will be used.
final String? icon;
/// The channel's id.
///
/// Required for Android 8.0 or newer.
final String channelId;
/// The channel's name.
///
/// Required for Android 8.0 or newer.
final String channelName;
/// The channel's description.
///
/// This property is only applicable to Android versions 8.0 or newer.
final String? channelDescription;
/// Whether notifications posted to this channel can appear as application
/// icon badges in a Launcher
final bool channelShowBadge;
/// The importance of the notification.
final Importance importance;
/// The priority of the notification
final Priority priority;
/// Indicates if a sound should be played when the notification is displayed.
///
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final bool playSound;
/// The sound to play for the notification.
///
/// Requires setting [playSound] to true for it to work.
/// If [playSound] is set to true but this is not specified then the default
/// sound is played.
///
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final AndroidNotificationSound? sound;
/// Indicates if vibration should be enabled when the notification is
/// displayed.
///
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final bool enableVibration;
/// Indicates if lights should be enabled when the notification is displayed.
///
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final bool enableLights;
/// Configures the vibration pattern.
///
/// Requires setting [enableVibration] to true for it to work.
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final Int64List? vibrationPattern;
/// Specifies the information of the rich notification style to apply to the
/// notification.
final StyleInformation? styleInformation;
/// Specifies the group that this notification belongs to.
///
/// For Android 7.0 or newer.
final String? groupKey;
/// Specifies if this notification will function as the summary for grouped
/// notifications.
final bool setAsGroupSummary;
/// Specifies the group alert behavior for this notification.
///
/// Default is AlertAll.
/// See https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setGroupAlertBehavior(int) for more details.
final GroupAlertBehavior groupAlertBehavior;
/// Specifies if the notification should automatically dismissed upon tapping
/// on it.
final bool autoCancel;
/// Specifies if the notification will be "ongoing".
final bool ongoing;
/// Specifies the color.
final Color? color;
/// Specifics the large icon to use.
final AndroidBitmap<Object>? largeIcon;
/// Specifies if you would only like the sound, vibrate and ticker to be
/// played if the notification is not already showing.
final bool onlyAlertOnce;
/// Specifies if the notification should display the timestamp of when it
/// occurred.
///
/// To control the actual timestamp of the notification, use [when].
final bool showWhen;
/// Specifies the timestamp of the notification.
///
/// To control whether the timestamp is shown in the notification, use
/// [showWhen].
///
/// The timestamp is expressed as the number of milliseconds since the
/// "Unix epoch" 1970-01-01T00:00:00Z (UTC). If it's not specified but a
/// timestamp should be shown (i.e. [showWhen] is set to `true`),
/// then Android will default to showing when the notification occurred.
final int? when;
/// Show [when] as a stopwatch.
///
/// Instead of presenting [when] as a timestamp, the notification will show an
/// automatically updating display of the minutes and seconds since [when].
/// Useful when showing an elapsed time (like an ongoing phone call).
final bool usesChronometer;
/// Sets the chronometer to count down instead of counting up.
///
/// This property is only applicable to Android 7.0 and newer versions.
final bool chronometerCountDown;
/// Specifies if the notification will be used to show progress.
final bool showProgress;
/// The maximum progress value.
final int maxProgress;
/// The current progress value.
final int progress;
/// Specifies if an indeterminate progress bar will be shown.
final bool indeterminate;
/// Specifies the light color of the notification.
///
/// For Android 8.0 or newer, this is tied to the specified channel and cannot
/// be changed after the channel has been created for the first time.
final Color? ledColor;
/// Specifies how long the light colour will remain on.
///
/// This property is only applicable to Android versions older than 8.0.
final int? ledOnMs;
/// Specifies how long the light colour will remain off.
///
/// This property is only applicable to Android versions older than 8.0.
final int? ledOffMs;
/// Specifies the "ticker" text which is sent to accessibility services.
final String? ticker;
/// The action to take for managing notification channels.
///
/// Defaults to creating the notification channel using the provided details
/// if it doesn't exist
final AndroidNotificationChannelAction channelAction;
/// Defines the notification visibility on the lockscreen.
final NotificationVisibility? visibility;
/// The duration in milliseconds after which the notification will be
/// cancelled if it hasn't already.
final int? timeoutAfter;
/// The notification category.
final AndroidNotificationCategory? category;
/// Specifies whether the notification should launch a full-screen intent as
/// soon as it triggers.
///
/// Note: The system UI may choose to display a heads-up notification,
/// instead of launching your full-screen intent, while the user is using the
/// device. When the full-screen intent occurs, the plugin will act as though
/// the user has tapped on a notification so handle it the same way
/// (e.g. via `onSelectNotification` callback) to display the appropriate
/// page for your application.
final bool fullScreenIntent;
/// Specifies the id of a published, long-lived sharing that the notification
/// will be linked to.
///
/// From Android 11, this affects if a messaging-style notification appears
/// in the conversation space.
final String? shortcutId;
/// Specifies the additional flags.
///
/// These flags will get added to the native Android notification's flags field: https://developer.android.com/reference/android/app/Notification#flags
/// For a list of a values, refer to the documented constants prefixed with "FLAG_" (without the quotes) at https://developer.android.com/reference/android/app/Notification.html#constants_1.
/// For example, use a value of 4 to allow the audio to repeat as documented at https://developer.android.com/reference/android/app/Notification.html#FLAG_INSISTEN
final Int32List? additionalFlags;
/// Specify a list of actions associated with this notifications.
///
/// Users will be able tap on the actions without actually launching the App.
/// Note that tapping a action will spawn a separate isolate that runs
/// **independently** from the main app.
final List<AndroidNotificationAction>? actions;
/// Provides some additional information that is displayed in the
/// notification.
///
/// No guarantees are given where exactly it is displayed. This information
/// should only be provided if it provides an essential benefit to the
/// understanding of the notification. The more text you provide the less
/// readable it becomes. For example, an email client should only provide the
/// account name here if more than one email account has been added.
///
/// As of Android 7.0 this information is displayed in the notification header
/// area. On Android versions before 7.0 this will be shown in the third line
/// of text in the platform notification template. You should not be using
/// setProgress(int, int, boolean) at the same time on those versions; they
/// occupy the same place.
final String? subText;
/// The notification tag.
///
/// Showing notification with the same (tag, id) pair as a currently visible
/// notification will replace the old notification with the new one, provided
/// the old notification was one that was not one that was scheduled. In other
/// words, the (tag, id) pair is only applicable for notifications that were
/// requested to be shown immediately. This is because the Android
/// AlarmManager APIs used for scheduling notifications only allow for using
/// the id to uniquely identify alarms.
final String? tag;
/// Specify coloring background should be enabled, if false, color will be
/// applied to app icon.
///
/// For most styles, the coloring will only be applied if the notification is
/// or a foreground service notification.
final bool colorized;
/// Set custom notification count.
///
/// Numbers are only displayed if the launcher application supports the
/// display of badges and numbers. If not supported, this value is ignored.
/// See https://developer.android.com/training/notify-user/badges#set_custom_notification_count
final int? number;
/// The attribute describing what is the intended use of the audio signal,
/// such as alarm or ringtone set in [`AudioAttributes.Builder`](https://developer.android.com/reference/android/media/AudioAttributes.Builder#setUsage(int))
/// https://developer.android.com/reference/android/media/AudioAttributes
final AudioAttributesUsage audioAttributesUsage;
}