1

I am developing a water remainder app in a flutter. I want a specific function to run on background even when the app is killed. I have a function that gives notification. I want that notification function to run on background even when the app is not running on the background, but I don't know where to call that function.

This is the notification function:

_scheduleNotify() async {
print("object");
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
var android = new AndroidInitializationSettings('@mipmap/ic_launcher');
var ios = new IOSInitializationSettings();
var initsetting = new InitializationSettings(android, ios);
flutterLocalNotificationsPlugin.initialize(initsetting);
var scheduledNotificationDateTime =
    new DateTime.now().add(new Duration(seconds: 5));
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
    'your other channel id',
    'your other channel name',
    'your other channel description');
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics = new NotificationDetails(
    androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
    0,
    'scheduled title',
    'scheduled body',
    scheduledNotificationDateTime,
    platformChannelSpecifics);

}

I have called this function every time the user gives input of intake. This works fine until the app is running. But if the app is closed or killed. This is not working. So where should I call this function to make this run even when the app is killed?

I didn't get any resources to implement this and I am a beginner in a flutter. Can someone help me with this? Thanks in advance.

Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
Siva Perumal
  • 457
  • 2
  • 8
  • 23
  • when in background or app killed, try scheduling a notification. https://github.com/MaikuB/flutter_local_notifications#scheduling-a-notification Hope you are using this plugin. – Amol Gangadhare Jun 03 '19 at 12:58
  • @AmolG I have tried scheduling notification and now I am not getting any notification. I have changed my previous function in my question above. can you help me here. – Siva Perumal Jun 04 '19 at 09:38

1 Answers1

0

The recommendation from this SO post could be applicable to your case:

For reminders i would recommend Flutter Local Notifications Plugin. It has a powerful scheduling api. From the documentation of local notification:

And for push notification, you can use Firebase Cloud Messaging or one signal plugin or you can implement natively through platform-channels

Edit: You can also fire notifications according to specific conditions even if the app is terminated. This can be achieved by running dart code in the background. Quoting from the official faq:

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65