本地通知抖动

2024-01-10

谁能用代码向我展示如何使用本地通知插件在 flutter 中安排通知。 尝试了 git 存储库中的示例,购买它对我不起作用,尽管正常通知正在工作,但我如何将其安排在特定时间(例如提醒)?


来自插件示例代码 https://github.com/MaikuB/flutter_local_notifications/blob/master/example/lib/main.dart如果你想安排一个通知,你必须使用这样的代码:

/// Schedules a notification that specifies a different icon, sound and vibration pattern
  Future _scheduleNotification() async {
    var scheduledNotificationDateTime =
        new DateTime.now().add(new Duration(seconds: 5));
    var vibrationPattern = new Int64List(4);
    vibrationPattern[0] = 0;
    vibrationPattern[1] = 1000;
    vibrationPattern[2] = 5000;
    vibrationPattern[3] = 2000;

    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
        'your other channel id',
        'your other channel name',
        'your other channel description',
        icon: 'secondary_icon',
        sound: 'slow_spring_board',
        largeIcon: 'sample_large_icon',
        largeIconBitmapSource: BitmapSource.Drawable,
        vibrationPattern: vibrationPattern,
        color: const Color.fromARGB(255, 255, 0, 0));
    var iOSPlatformChannelSpecifics =
        new IOSNotificationDetails(sound: "slow_spring_board.aiff");
    var platformChannelSpecifics = new NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.schedule(
        0,
        'scheduled title',
        'scheduled body',
        scheduledNotificationDateTime,
        platformChannelSpecifics);
  }

您必须关注的部分是:

// Schedule a notification in 5 secs from now
var scheduledNotificationDateTime =
        new DateTime.now().add(new Duration(seconds: 5));

如果您不确定要显示通知的本机项目设置,我建议您克隆插件存储库并尝试其示例。

/// 重要提示:单独运行以下代码将不起作用 每个平台头项目都需要进行设置。

/// 请 从 GitHub 存储库下载完整的示例应用程序,其中所有内容 设置已完成

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

本地通知抖动 的相关文章

随机推荐