Show recurring local push notification in custom time interval - flutter

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');
});

Related

flutter local notification can't set notification for next day

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,

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

FCM : Cant get a pop up notification when app is running in background

I am using "Firebase Cloud Messaging" for receiving notifications and "flutter_local_notifications" plugin to configure and display them on my device. So my current scenario is when my app is running (in foreground), I am receiving proper notification as expected (a pop-up plus it gets stored in system-tray) like this :
It also gets stored in the system tray as expected.
But when I keep the app in background and post a notification request ........ It just stores the notification in the tray but doesnt show a pop-up notification. Like this :
As seen in the image above .... it just stores the notification in the image tray but doesn't show pop-up notification like when the app is running in foreground.
I thought I was an issue in the "backgroundMessage" Callback but what I observed was whenever I posted a notification when the app is in background, instead of executing the "backgroundMessage" callback it always gave this exception :
W/FirebaseMessaging(22744): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
Below is the code where I configured the FirebaseMessaging instance :
_firebaseMessaging.configure(
onMessage: notification,
onBackgroundMessage: notificationBack,
);
'notification' Callback :
Future<dynamic> notification(Map<String,dynamic> message) async {
AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'Channel ID', 'Channel title', 'channel body',
priority: Priority.High,
importance: Importance.Max,
ticker: 'test');
IOSNotificationDetails iosNotificationDetails = IOSNotificationDetails();
NotificationDetails notificationDetails =
NotificationDetails(androidNotificationDetails, iosNotificationDetails);
await _flutterLocalNotificationsPlugin.show(
0, 'Notification', 'New Notification', notificationDetails);
}
'notificationBack' callback :
static Future<dynamic> notificationBack(Map<String,dynamic> message) async {
AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'Channel ID', 'Channel title', 'channel body',
priority: Priority.High,
importance: Importance.Max,
visibility: NotificationVisibility.Public,
ticker: 'test');
IOSNotificationDetails iosNotificationDetails = IOSNotificationDetails();
NotificationDetails notificationDetails =
NotificationDetails(androidNotificationDetails, iosNotificationDetails);
await _flutterLocalNotificationsPluginBack.show(
0, 'Hello there', 'please subscribe my channel', notificationDetails);
}
AndroidManifest.xml :
Sorry for the screenshot instead of text format .... but I dont know why all these terms were highlighted in red saying "Cant resolve symbol ...." and "Unresolved package 'flutterlocalnotifications'" in case of reciever of flutterlocalnotification.
My main goal is to get the game pop-up notification and one in the system tray even when the app is in background. (Just how it displayed when it was in foreground).
I know the question is a bit long but I had to provide all my observation about the issue so please bare with it :)
Thankyou in advance for the help.

Daily push notification using flutter without firebase?

I developed app using flutter.
I want to develop push notification setting screen.
User can set push notification time using this page.
And It is daily noti to user at user's setting time.
This is my flutter code, but nothing happening!
Please help me what I modified the code.
Future _showNotificationWithSound() async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.Max, priority: Priority.High);
var iosPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(androidPlatformChannelSpecifics, iosPlatformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(
1,
'Title',
'Contents! :)',
platformChannelSpecifics,
);
}
As the Plugin's readme states, you can schedule a daily notification using showDailyAtTime method rather than using show method:
var time = Time(10, 0, 0);
var androidPlatformChannelSpecifics =
AndroidNotificationDetails('repeatDailyAtTime channel id',
'repeatDailyAtTime channel name', 'repeatDailyAtTime description');
var iOSPlatformChannelSpecifics =
IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showDailyAtTime(
0,
'show daily title',
'Daily notification shown at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}',
time,
platformChannelSpecifics
);