【问题标题】:showing notifications using flutter使用颤振显示通知
【发布时间】:2020-10-28 20:27:28
【问题描述】:

我使用颤振本地通知插件,但我不知道如何使用 flutterLocalNotificationsPlugin.zonedSchedule。注意到我不能使用 flutterLocalNotificationsPlugin.showDailyAtTime 因为它已被弃用

【问题讨论】:

标签: flutter dart push-notification notifications


【解决方案1】:

而不是这个:

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

你可以用这个:

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,
);

我没有测试它,但这应该在每天 18:02 重复。 记得添加这个包:

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

【讨论】:

    猜你喜欢
    • 2021-07-22
    • 2020-07-31
    • 2022-08-22
    • 2021-09-28
    • 2021-04-28
    • 2021-12-28
    • 1970-01-01
    • 2020-01-26
    相关资源
    最近更新 更多