Open FarhanAli001 opened 4 years ago
I am making alarm application and i want the alarm to be called at the set time even the app is killed and show notification with the ringing alarm and buttons to stop and sneeze the alarm, i will be very thankful to you if anyone help me
Hi ! This ,of course, can be done with two different libraries, used in the same project : 1) flutter_local_notifications 2) background_fetch
In the first manner, for setting the exact time, you need to do the following:
void _scheduleTime() { var scheduledNotificationDateTime = DateTime.now().add(Duration(seconds: 30); var androidPlatformChannelSpecifics = AndroidNotificationDetails('your other channel id', 'your other channel name', 'your other channel description'); var iOSPlatformChannelSpecifics = IOSNotificationDetails(); NotificationDetails platformChannelSpecifics = NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); await flutterLocalNotificationsPlugin.schedule( 0, 'scheduled title', 'scheduled body', scheduledNotificationDateTime, platformChannelSpecifics); }
in the method above, you see that for the next 30 seconds, you'll get a notification. you should measure current time, get user alarm time and calculate when the alarm launches. Here, alarm is actually a notif and you can customize that relatively.
In second case, you can use background_fetch library and check the time in the background. But remember that you can check it just every 15 mins (according to android & IOS limitations) which is not so cool !!
Good Luck !!
I am making alarm application and i want the alarm to be called at the set time even the app is killed and show notification with the ringing alarm and buttons to stop and sneeze the alarm, i will be very thankful to you if anyone help me