Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_local_notifications] Add "selectable" property for AndroidNotificationDetails to disable click actions on the notification #2331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ protected static Notification createNotification(
: notificationDetails.body)
.setTicker(notificationDetails.ticker)
.setAutoCancel(BooleanUtils.getValue(notificationDetails.autoCancel))
.setContentIntent(pendingIntent)
.setContentIntent(
BooleanUtils.getValue(notificationDetails.selectable)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to other parts of the code, I don't believe you should be using BooleanUtils.getValue(). That is for coalescing null values to false. The null values would happen when introducing new fields/properties and there are scheduled notifications kept in shared preferences. With the changes introduced in the PR, my understanding is that null selectable value be coalesced to true instead of false

? pendingIntent
: null)
.setPriority(notificationDetails.priority)
.setOngoing(BooleanUtils.getValue(notificationDetails.ongoing))
.setSilent(BooleanUtils.getValue(notificationDetails.silent))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class NotificationDetails implements Serializable {
private static final String REPEAT_TIME = "repeatTime";
private static final String PLATFORM_SPECIFICS = "platformSpecifics";
private static final String AUTO_CANCEL = "autoCancel";
private static final String SELECTABLE = "selectable";
private static final String ONGOING = "ongoing";
private static final String SILENT = "silent";
private static final String STYLE = "style";
Expand Down Expand Up @@ -153,6 +154,7 @@ public class NotificationDetails implements Serializable {
public Boolean setAsGroupSummary;
public Integer groupAlertBehavior;
public Boolean autoCancel;
public Boolean selectable;
public Boolean ongoing;
public Boolean silent;
public Integer day;
Expand Down Expand Up @@ -246,6 +248,7 @@ private static void readPlatformSpecifics(
(Map<String, Object>) arguments.get(PLATFORM_SPECIFICS);
if (platformChannelSpecifics != null) {
notificationDetails.autoCancel = (Boolean) platformChannelSpecifics.get(AUTO_CANCEL);
notificationDetails.selectable = (Boolean) platformChannelSpecifics.get(SELECTABLE);
notificationDetails.ongoing = (Boolean) platformChannelSpecifics.get(ONGOING);
notificationDetails.silent = (Boolean) platformChannelSpecifics.get(SILENT);
notificationDetails.style =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails {
'setAsGroupSummary': setAsGroupSummary,
'groupAlertBehavior': groupAlertBehavior.index,
'autoCancel': autoCancel,
'selectable': selectable,
'ongoing': ongoing,
'silent': silent,
'colorAlpha': color?.alpha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class AndroidNotificationDetails {
this.setAsGroupSummary = false,
this.groupAlertBehavior = GroupAlertBehavior.all,
this.autoCancel = true,
this.selectable = true,
this.ongoing = false,
this.silent = false,
this.color,
Expand Down Expand Up @@ -237,6 +238,14 @@ class AndroidNotificationDetails {
/// Specifies if the notification should automatically dismissed upon tapping
/// on it.
final bool autoCancel;

/// Specifies if the notification is selectable.
///
/// If `selectable` is `false`, the `contentIntent` will be set to `null`,
/// disabling click actions on the notification.
///
/// The default value is `true`.
final bool selectable;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can you update the example app to include a scenario that makes use of this?
  • I assume the onSelectNotification callback won't fire. Can you confirm? If so, can you update the API docs to explicitly add mention of this. Some developers may not realise the implication based on reading what's there


/// Specifies if the notification will be "ongoing".
final bool ongoing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -262,6 +263,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -346,6 +348,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -431,6 +434,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -517,6 +521,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -607,6 +612,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -696,6 +702,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -783,6 +790,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': true,
'colorAlpha': null,
Expand Down Expand Up @@ -871,6 +879,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -961,6 +970,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1066,6 +1076,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1165,6 +1176,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1270,6 +1282,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1367,6 +1380,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1468,6 +1482,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1560,6 +1575,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1649,6 +1665,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1745,6 +1762,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1870,6 +1888,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -1983,6 +2002,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -2081,6 +2101,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -2178,6 +2199,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -2276,6 +2298,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': null,
Expand Down Expand Up @@ -2576,6 +2599,7 @@ void main() {
'setAsGroupSummary': false,
'groupAlertBehavior': GroupAlertBehavior.all.index,
'autoCancel': true,
'selectable': true,
'ongoing': false,
'silent': false,
'colorAlpha': 255,
Expand Down
Loading