I am actually showing a notification that indicates the remaining time of the Booking of the Vehicle parked at the parking lot.
eg. From Booking_Time = 2022-10-10 12:25 To Booking_Time = 2022-10-10 18:25
so the problem is, suppose the time remaining is 06:25:00. In the notification it starts properly but no matter what the value for chronometerCountDown = true/false the timer goes upward only. if chronometerCountDown = false it shows 06:25:00, 06:25:01, 06:25:02, 06:25:03...this is as expected if chronometerCountDown = true it shows -06:25:00, -06:25:01, -06:25:02, -06:25:03...going upward only
Below is my AndroidNOtificationDetails ::
DateTime whenTimer =
currentTime.subtract(durationElapsed);
AndroidNotificationDetails and = AndroidNotificationDetails(
'sample_vehicle',
'Vehicle Parking Time Remaining',
channelDescription:
'Notify the user that vehicle\'s time of booking...',
importance: Importance.max,
priority: Priority.max,
channelShowBadge: false,
ticker: 'sample_vehicle',
color: Colors.blue,
onlyAlertOnce: true,
when: whenTimer.millisecondsSinceEpoch,
timeoutAfter: whenTimer.difference(DateTime.now()).inMilliseconds,
usesChronometer: true,
chronometerCountDown: true,
visibility: NotificationVisibility.public,
ongoing: true,
);
I hope I have mentioned my problem properly.
NOTE: I have checked the example and it shows same behaviour
when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, usesChronometer: true, chronometerCountDown: true,
In short chronometerCountDown: true only adds the "-" sign nothing else.
Here I got the answer to my question on Github forum of the flutter_local_notification only.
If we use chronometerCountDown: false the value of when: DateTime.now().millisecondsSinceEpoch - 120 * 1000
, shows we have subtracted 2 mins from the current epoch time and so it will count up to fill the gap.
Since I was counting down, I needed to add to the when time, not subtract means,
when: DateTime.now().millisecondsSinceEpoch + 120 * 1000
, which shows that we have added 2 mins and now it has to count down to fill the gap.
currentTime.subtract(durationElapsed);
//Here countUp will work
currentTime.add(durationElapsed);
//Here countDown will work
Here is the full example code :
DateTime currentTime = DateTime.now();
DateTime whenTimer = currentTime.add(durationElapsed);
AndroidNotificationDetails and = AndroidNotificationDetails(
'sample_vehicle',
'Vehicle Parking',
channelDescription:
'Notify the user that vehicle\'s time of booking ...',
importance: Importance.max,
priority: Priority.max,
channelShowBadge: true,
ticker: 'sample_vehicle',
color: Colors.blue,
onlyAlertOnce: true,
when: whenTimer.millisecondsSinceEpoch,
timeoutAfter: whenTimer.difference(currentTime).inMilliseconds,
usesChronometer: true,
chronometerCountDown: true,
visibility: NotificationVisibility.public,
ongoing: true,
);