【发布时间】:2021-02-16 03:40:02
【问题描述】:
如何在 Flutter 中安排每月或每周通知?目的是为了提醒用户某事......
这是我的代码
void showMonthlyAtDayTime() async {
//var scheduledNotificationDateTime = DateTime.now().add(Duration(seconds: 10));
var time = Time(12, 6, 0);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'alarm_notif',
'Scheduled notification', // name of the notif channel
'A scheduled notification', // description of the notif channel
icon: 'question',
largeIcon: DrawableResourceAndroidBitmap('question'),
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true);
var platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.showMonthlyAtDayTime(
0,
'Title',
'Body',
Day.Tuesday,
time,
platformChannelSpecifics);
}
代码中的 showMonthlyAtDayTime 下方有(红色)下划线
'等待flutterLocalNotificationsPlugin.showMonthlyAtDayTime'行
还有“Day.Tuesday”行...
我应该如何修改上面的代码?这样用户每年每个月都会收到一次有关某事的通知。
【问题讨论】:
-
你为什么不使用推送通知来实现同样的效果,而不是从前端创建通知。
-
你是怎么做到的?我是 Flutter 开发的初学者
-
我刚刚更新了问题描述......关于火扑的事情,我在与 firebase 集成时遇到了很多麻烦......我不知道为什么,不是代码,而是pod 文件案例...
-
您不需要使用远程 (PUSH) 通知来进行提醒。计划提醒最好在没有服务器端的情况下使用本地通知创建。因此,如果您使用 flutter_local_notifications 插件,您就走在了正确的道路上。为什么它不起作用 - 可能有几个原因。请检查您是否错过了插件设置中的任何内容 - pub.dev/packages/flutter_local_notifications#-android-setup 和 pub.dev/packages/flutter_local_notifications#-ios-setup
标签: flutter flutter-dependencies