flutter local notification can't set notification for next day - flutter

I use flutter local notification package in my project and when I try to set a notification in custom day it doesn't work .
for example : if I set notification for tomorrow at 3:15 it will range in the day I set the notification in not "in the next day" , Here is my code after adding custom time for notification to test this case
await flutterLocalNotificationsPlugin.zonedSchedule(
task.id!.toInt(),
task.title,
task.note,
tz.TZDateTime(tz.local, now.year, now.month, now.day + 1, 15, 17),
// _convertTime(hour, minutes, task),
const NotificationDetails(
android: AndroidNotificationDetails(
'your channel id 3',
'your channel name',
channelDescription: 'your channel description',
priority: Priority.max,
importance: Importance.max,
sound: RawResourceAndroidNotificationSound('notification_sound'),
),
iOS: DarwinNotificationDetails(sound: 'notification_sound.wav'),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
payload: "${task.title}|${task.note}|${task.date}|",
);
}
can you help me with a way to set the notification for a spacific day 😓

I found that this error happen because I set
matchDateTimeComponents: DateTimeComponents.time,
and that tell the app to run this every day so even if you set it for tomorrow it will also run today so I solved that by setting this to
matchDateTimeComponents: DateTimeComponents.dateAndTime,

Related

Flutter schedule notifications

anybody knows how to set local notification to show everyday another notification but with the same title cause with my code i get only the same notification body over and over again. I'm struggling for some days working on it. Anybody knows how to make it work?
Here's my notification code:
Future<void> showNotification(int id, String title, String body) async {
await flutterLocalNotificationsPlugin.periodicallyShow(
id,
title,
body,
RepeatInterval.everyMinute,
const NotificationDetails(
// Android details
android: AndroidNotificationDetails('main_channel', 'Main Channel',
channelDescription: "ashwin",
importance: Importance.max,
priority: Priority.max),
// iOS details
iOS: DarwinNotificationDetails(
sound: 'default.wav',
presentAlert: true,
presentBadge: true,
presentSound: true,
),
),
androidAllowWhileIdle:
true, // To show notification even when the app is closed
);
}
I want to schedule different notification when notification it s called.

Flutter reminder app alarm notification return value

I am writing a reminder application using flutter. I want it to send notifications for the tasks entered at that date and time, even if the application is closed. Its notification should be like the phone's default alarm app. Confirmation snooze buttons and sounds. I'll need what the user did with this notification on another page. I am not using a database. Is there an easy way to do these operations?
You can either use awesome_notifications or flutter_local_notifications
flutter_local_notifications example
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'scheduled title',
'scheduled body',
tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
const NotificationDetails(
android: AndroidNotificationDetails(
'your channel id', 'your channel name',
channelDescription: 'your channel description')),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
awesome_notifications example
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'scheduled',
title: 'wait 5 seconds to show',
body: 'now is 5 seconds later',
wakeUpScreen: true,
category: NotificationCategory.Alarm,
),
schedule: NotificationInterval(
interval: 5,
timeZone: localTimeZone,
preciseAlarm: true,
timezone: await AwesomeNotifications().getLocalTimeZoneIdentifier()
);
Use the awesome-notifications package!
Package on pub.dev:- https://pub.dev/packages/awesome_notifications
To install the package, use the command:-
flutter pub add awesome-notifications

Flutter Notifications after one hour

Hello I need to make local notification on mobile whenever a button is pressed. And i don't want to make the notification instantly but after one hour when the user hit that button does anyone have any idea?
I tried this plugin flutter_local_notifications: ^8.2.0
But can some help me how to do the trigger after one hour
Thanks
Use this function to call notifications every hour
shownotifications() async {
const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('repeating channel id',
'repeating channel name', 'repeating description');
const NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await FlutterLocalNotificationsPlugin().periodicallyShow(0, 'Test title',
'test body', RepeatInterval.hourly, platformChannelSpecifics,
androidAllowWhileIdle: true);
}
and follow this article step by step to to setup the package you are using

How to repeat local notification every day with dart-flutter? and how to parse '2:00 AM' time format To TimeZone?

I am trying to make a daily remainder to patient's medicine timings, I am using flutter_local_notifications and it works well.
this is my function i want to make it repeats daily,
void scheduleAlarm() async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'alarm_notif',
'alarm_notif',
'Channel for Alarm notification',
icon: 'codex_logo',
sound: RawResourceAndroidNotificationSound('notification_sound'),
largeIcon: DrawableResourceAndroidBitmap('drug'),
);
tz.initializeTimeZones();
tz.setLocalLocation(tz.getLocation('America/Detroit'));
var iOSPlatformChannelSpecifics = IOSNotificationDetails(
sound: 'notification_sound.wav',
presentAlert: true,
presentBadge: true,
presentSound: true);
var platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'Panadol',
'Don\'t forget to take your medicine 2:00 AM',
tz.TZDateTime.now(tz.local).add(Duration(seconds: 5)),
platformChannelSpecifics,
androidAllowWhileIdle: true,
);
}
and I want to change this line so I could pass a string of timing that I got from TimePicker in this formate '2:00 AM'
tz.TZDateTime.now(tz.local).add(Duration(seconds: 5)),
With your existing code, you can use the cron module like this to schedule an everyday notification.
cron.schedule(Schedule.parse('0 2 */1 * *'), () async {
scheduleAlarm();
print('Run scheduled notification');
});
Please note that your notification is delayed by 5 seconds, but note that zonedSchedule() need a future date too to be executed.
You can use crontab.guru to help you if you're not handy with cron expression.
NOTE: Cron need the app to be running to work.

Show recurring local push notification in custom time interval

I want to show push notification to user in every 30 minutes but Flutter Local Notification Plugin has limitation that it supports the repeat intervals (EveryMinute, Hourly, Daily, Weekly).
What are the alternative that I can approach to?
How about you use Timer and Flutter Local Notificaion Plugin like below?
Timer.periodic(Duration(minutes: 30), () {
// Make a local notification
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0, 'plain title', 'plain body', platformChannelSpecifics,
payload: 'item x');
});