【问题标题】:Schedule notification using flutter_local_notifications使用 flutter_local_notifications 安排通知
【发布时间】:2021-01-30 23:35:58
【问题描述】:

我正在使用flutter_local_notifications 插件向我的用户发送通知。但我需要安排通知。所以我使用zonedSchedule() 来做到这一点。 问题是zonedSchedule()需要TZDateTime,所以我需要将DateTime转换为TZDateTime。我看到this 的问题,但它对我不起作用。我只需要获取用户的Location 并传递给TZDateTime.from(dateTime,location)。我怎样才能得到这个位置?

提前致谢。

【问题讨论】:

    标签: flutter dart push-notification dart-pub


    【解决方案1】:

    我刚刚问过这个问题,但我已经有了答案。对于Location 遇到问题的人,您可以使用tz.getLocation(await FlutterNativeTimezone.getLocalTimezone()) 来获取TZDateTime.from(dateTime,location)location 参数。

    PS.:记得导入:import 'package:timezone/data/latest.dart' as tz;import 'package:timezone/timezone.dart' as tz;.

    另外,你必须初始化tz:

    tz.initializeTimeZones();
    tz.setLocalLocation(tz.getLocation(await FlutterNativeTimezone.getLocalTimezone()));
    

    就是这样,希望有用。

    【讨论】:

    • flutter_local_notifications 的文档中也写了这个
    猜你喜欢
    • 2019-09-26
    • 2019-09-06
    • 1970-01-01
    • 2014-12-07
    • 2021-09-28
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 2020-04-23
    相关资源
    最近更新 更多