重复通知 - Flutter

5

我该如何在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);
}

代码中在 'wait flutterLocalNotificationsPlugin.showMonthlyAtDayTime' 行和 'Day.Tuesday' 行出现了 (红色) 下划线。
如何修改上述代码?以便用户每年每月仅收到一次关于某事的通知。

为什么不使用推送通知来实现相同的功能,而是从前端创建通知? - Shubham Gupta
你怎么做到的?我是Flutter开发的初学者。 - Sarah ED
您可以观看此视频 https://fireship.io/lessons/flutter-push-notifications-fcm-guide/。 - Shubham Gupta
我刚刚更新了问题描述...关于Fire Flutter的事情,我在与Firebase集成方面遇到了很多麻烦...我不确定为什么,这不是代码的问题,而是Pod文件的情况... - Sarah ED
提醒功能不需要使用远程(PUSH)通知。最好使用本地通知创建定时提醒而无需借助服务器端。如果使用flutter_local_notifications插件,那么您正在正确的道路上。为何它不能正常工作——可能有几个原因。请检查是否漏掉了插件设置的任何内容 - https://pub.dev/packages/flutter_local_notifications#-android-setup 和 https://pub.dev/packages/flutter_local_notifications#-ios-setup - Mol0ko
1个回答

1
最新版本中删除了一些方法。
这是我找到的使用flutter_local_notifications每周重复通知的代码。
Future<void> _scheduleWeeklyTenAMNotification() async {
await notificationsPlugin.zonedSchedule(
    0,
    'weekly scheduled notification title',
    'weekly scheduled notification body',
    _nextInstanceOfTenAM(),
    const NotificationDetails(
      android: AndroidNotificationDetails(
          'weekly notification channel id',
          'weekly notification channel name',
          'weekly notificationdescription'),
    ),
    androidAllowWhileIdle: true,
    uiLocalNotificationDateInterpretation:
    UILocalNotificationDateInterpretation.absoluteTime,
    matchDateTimeComponents: DateTimeComponents.dayOfWeekAndTime);
  }
  tz.TZDateTime _nextInstanceOfTenAM() {
    final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
    tz.TZDateTime scheduledDate =
    tz.TZDateTime(tz.local, now.year, now.month, now.day, 10);
    if (scheduledDate.isBefore(now)) {
      scheduledDate = scheduledDate.add(const Duration(days: 1));
    }
    return scheduledDate;
  }

这段代码是从https://pub.dev/packages/flutter_local_notifications提供的示例应用程序中复制的。

这里是 Git Hub 链接 点击此处


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接