Mohamed Shmela
Mohamed Shmela

Reputation: 61

showing notifications using flutter

I use the flutter local notifications plugin but I don't know how to schedule notifications using flutterLocalNotificationsPlugin.zonedSchedule. noted that I can't use flutterLocalNotificationsPlugin.showDailyAtTime because it's deprecated

Upvotes: 1

Views: 1656

Answers (1)

cansu
cansu

Reputation: 1144

Instead of this :

await flutterLocalNotificationsPlugin.showDailyAtTime(
0, 'Title', 'Body', time, platformChannel,
payload: 'New payload');

You can use this :

var dateTime = DateTime(DateTime.now().year, DateTime.now().month,
    DateTime.now().day, 18, 2, 0);
    await flutterLocalNotificationsPlugin.zonedSchedule(
  0,
  'scheduled title',
  'scheduled body',
  tz.TZDateTime.from(dateTime, tz.local),
  platformChannel,
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation.absoluteTime,
  matchDateTimeComponents: DateTimeComponents.time,
);

I didn't test it, but this should repeat every day at 18:02. Remember to add this package:

import 'package:timezone/data/latest.dart' as tz;

Upvotes: 1

Related Questions