【问题标题】:Local Schedule Notification in FlutterFlutter 中的本地调度通知
【发布时间】:2021-10-12 12:29:53
【问题描述】:

我想每天在特定时间触发本地通知(由用户选择)。类似于报警类型。在日期选择器的帮助下。用户必须选择日期和时间,它应该每天在该时间推送本地通知。

【问题讨论】:

    标签: flutter notifications alarmmanager localnotification


    【解决方案1】:

    假设你已经预设了flutter_local_notification

    您可以按照以下方式进行操作

    DateTime scheduledTime 处理日期时间分配

    import 'package:flutter_local_notifications/flutter_local_notifications.dart'as notifs;
    Future<void> scheduleNotification(
        {notifs.FlutterLocalNotificationsPlugin notifsPlugin,
        String id,
        String title,
        String body,
        DateTime scheduledTime}) async {
      var androidSpecifics = notifs.AndroidNotificationDetails(
        id, // This specifies the ID of the Notification
        'Scheduled notification', // This specifies the name of the notification channel
        'A scheduled notification', //This specifies the description of the channel
        icon: 'icon',
      );
      var iOSSpecifics = notifs.IOSNotificationDetails();
      var platformChannelSpecifics = notifs.NotificationDetails(
          androidSpecifics, iOSSpecifics);
      await notifsPlugin.schedule(0, title, "Scheduled notification",
          scheduledTime, platformChannelSpecifics); // This literally schedules the notification
    

    }

    用户将如何选择日期(在特定时间每天应触发多少天本地通知

    如果是一次出现通知,您可以使用日期时间选择器来选择日期

    如果它必须在不同的日子同时发生,您可以使用workmanager 并每 24 小时运行一次,并在没有频率结束后结束服务

    检查这个blog post

    【讨论】:

    • 你可以在这里阅读更多medium.com/@fuzzymemory/…
    • 用户如何选择日期(每天在特定时间触发多少天本地通知)?我不希望它硬编码。用户必须使用 datepicker 或其他东西选择日期。
    猜你喜欢
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 2021-03-23
    • 2021-10-16
    • 2022-12-07
    • 2020-12-03
    • 2020-11-26
    • 2022-12-07
    相关资源
    最近更新 更多