Skip to content

Commit

Permalink
[flutter_local_notifications] Fixes #1486 :Adds ability to count down…
Browse files Browse the repository at this point in the history
… chronometer with chronometerCountDown (#1778)

* Adds ability to count down chronometer with chronometerCountDown

* Fix: Api doc correction for chronometerCountDown

* Fix: Added 'chronometerCountDown' for unit tests

* fix casing used for chronometerCountDown api doc

Co-authored-by: Edgars Belevics <>
Co-authored-by: Michael Bui <25263378+MaikuB@users.noreply.github.com>
  • Loading branch information
ebelevics and MaikuB committed Dec 3, 2022
1 parent 2380680 commit cb05fb7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
Expand Up @@ -347,6 +347,12 @@ protected static Notification createNotification(
builder.setUsesChronometer(notificationDetails.usesChronometer);
}

if (notificationDetails.chronometerCountDown != null) {
if (VERSION.SDK_INT >= VERSION_CODES.N) {
builder.setChronometerCountDown(notificationDetails.chronometerCountDown);
}
}

if (BooleanUtils.getValue(notificationDetails.fullScreenIntent)) {
builder.setFullScreenIntent(pendingIntent, true);
}
Expand Down
Expand Up @@ -108,6 +108,7 @@ public class NotificationDetails implements Serializable {
private static final String SHOW_WHEN = "showWhen";
private static final String WHEN = "when";
private static final String USES_CHRONOMETER = "usesChronometer";
private static final String CHRONOMETER_COUNT_DOWN = "chronometerCountDown";
private static final String ADDITIONAL_FLAGS = "additionalFlags";

private static final String SCHEDULED_DATE_TIME = "scheduledDateTime";
Expand Down Expand Up @@ -173,6 +174,7 @@ public class NotificationDetails implements Serializable {
public int[] additionalFlags;
public Boolean showWhen;
public Boolean usesChronometer;
public Boolean chronometerCountDown;
public String scheduledDateTime;
public String timeZoneName;
public ScheduledNotificationRepeatFrequency scheduledNotificationRepeatFrequency;
Expand Down Expand Up @@ -255,6 +257,8 @@ private static void readPlatformSpecifics(
notificationDetails.when = LongUtils.parseLong(platformChannelSpecifics.get(WHEN));
notificationDetails.usesChronometer =
(Boolean) platformChannelSpecifics.get(USES_CHRONOMETER);
notificationDetails.chronometerCountDown =
(Boolean) platformChannelSpecifics.get(CHRONOMETER_COUNT_DOWN);
readProgressInformation(notificationDetails, platformChannelSpecifics);
readColor(notificationDetails, platformChannelSpecifics);
readChannelInformation(notificationDetails, platformChannelSpecifics);
Expand Down
1 change: 1 addition & 0 deletions flutter_local_notifications/example/lib/main.dart
Expand Up @@ -2172,6 +2172,7 @@ class _HomePageState extends State<HomePage> {
priority: Priority.high,
when: DateTime.now().millisecondsSinceEpoch - 120 * 1000,
usesChronometer: true,
chronometerCountDown: true,
);
final NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
Expand Down
Expand Up @@ -196,6 +196,7 @@ extension AndroidNotificationDetailsMapper on AndroidNotificationDetails {
'showWhen': showWhen,
'when': when,
'usesChronometer': usesChronometer,
'chronometerCountDown': chronometerCountDown,
'showProgress': showProgress,
'maxProgress': maxProgress,
'progress': progress,
Expand Down
Expand Up @@ -122,6 +122,7 @@ class AndroidNotificationDetails {
this.showWhen = true,
this.when,
this.usesChronometer = false,
this.chronometerCountDown = false,
this.channelShowBadge = true,
this.showProgress = false,
this.maxProgress = 0,
Expand Down Expand Up @@ -274,6 +275,11 @@ class AndroidNotificationDetails {
/// 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;

Expand Down
Expand Up @@ -147,6 +147,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -267,6 +268,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -349,6 +351,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -432,6 +435,7 @@ void main() {
'showWhen': true,
'when': timestamp,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -516,6 +520,7 @@ void main() {
'showWhen': true,
'when': timestamp,
'usesChronometer': true,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -604,6 +609,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -691,6 +697,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -777,6 +784,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -865,6 +873,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -968,6 +977,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1065,6 +1075,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1168,6 +1179,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1263,6 +1275,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1362,6 +1375,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1452,6 +1466,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1539,6 +1554,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1633,6 +1649,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1756,6 +1773,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1867,6 +1885,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -1962,6 +1981,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -2056,6 +2076,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -2151,6 +2172,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down Expand Up @@ -2444,6 +2466,7 @@ void main() {
'showWhen': true,
'when': null,
'usesChronometer': false,
'chronometerCountDown': false,
'showProgress': false,
'maxProgress': 0,
'progress': 0,
Expand Down

0 comments on commit cb05fb7

Please sign in to comment.