简体   繁体   English

如何使用 Flutter 中的 awesome 包在特定时间安排通知?

[英]How to schedule notification at specific time using awesome package in Flutter?

I am using an awesome Package and am trying to make a notification at a specific time using this package.我正在使用一个很棒的包,并尝试使用此包在特定时间发出通知。

Future<void> showNotificationWithIconsAndActionButtons(int id) async {
    AwesomeNotifications().initialize(
        '',
        [
          NotificationChannel(
              channelKey: 'basic_channel',
              channelName: 'Basic notifications',
              channelDescription: 'Notification channel for basic tests',
              defaultColor: Color(0xFF9D50DD),
              ledColor: Colors.white,
            playSound: true,

            importance: NotificationImportance.Max,
            defaultRingtoneType: DefaultRingtoneType.Notification,

          )
        ]
    );
 
    await AwesomeNotifications().createNotification(

        content: NotificationContent(
            id: id,
            channelKey: 'basic_channel',
            title: 'Anonymous says:',
            body: 'Hi there!',
            payload: {'uuid': 'user-profile-uuid'},
          displayOnBackground: true,
          displayOnForeground: true,

            ),
        
     

i need to make notification in particular time.我需要在特定时间发出通知。

The same plugin provides a way to schedule notifications as per the need.相同的插件提供了一种根据需要安排通知的方法。

Checkout this link from it's description: https://pub.dev/packages/awesome_notifications#scheduling-a-notification从它的描述中查看此链接: https : //pub.dev/packages/awesome_notifications#scheduling-a-notification

Bascially showing it at a specific time will look something like this:基本上在特定时间显示它看起来像这样:

 await AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: id,
    channelKey: 'scheduled',
    title: 'Just in time!',
    body: 'This notification was schedule to shows at ' +
        (Utils.DateUtils.parseDateToString(scheduleTime.toLocal()) ?? '?') +
        ' $timeZoneIdentifier (' +
        (Utils.DateUtils.parseDateToString(scheduleTime.toUtc()) ?? '?') +
        ' utc)',
    notificationLayout: NotificationLayout.BigPicture,
    bigPicture: 'asset://assets/images/delivery.jpeg',
    payload: {'uuid': 'uuid-test'},
    autoCancel: false,
  ),
  schedule: NotificationCalendar.fromDate(date: scheduleTime));

Note: The code sample is from the plugin's Readme.注意:代码示例来自插件的自述文件。 I have not tested this yet.我还没有测试过这个。

Timer.periodic(Duration(minutes: 1), (timer) {
      if (DateTime.now()== DateTime.parse("2021-07-20 20:18:04Z")){// 8:18pm
        return showNotificationWithIconsAndActionButtons();
      }
    });

This will let it check the time every minute.这将让它每分钟检查一次时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Flutter 中的特定时间安排警报? - How to schedule an alarm on specific time in Flutter? Flutter 真棒通知 点击打开特定页面 - Flutter awesome notification click open specific page 使用 firebase 在 flutter 中安排通知 - Schedule notification in flutter using firebase 如何在颤动中安排多个时间特定的本地通知 - How to schedule multiple time specific local notifications in flutter 使用 flutter_local_notifications 安排通知 - Schedule notification using flutter_local_notifications 如何使用android_alarm_manager_plus FLUTTER package在Flutter中设置Android闹钟的具体时间? - How to set the specific time in Android Alarm Clock in Flutter using android_alarm_manager_plus FLUTTER package? 如何在Flutter中安排通知? - How do I schedule a notification in Flutter? 有没有办法使用颤振本地通知同时安排多个通知 - is there any way to schedule multiple notifications at same time using flutter local notification 可以在特定时间使用 FCM IN FLUTTER 发送推送通知 - It is Possible to send Push notification at specific time Using FCM IN FLUTTER Flutter:计划通知不起作用 - Flutter: Schedule notification not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM