简体   繁体   English

本地通知抖动

[英]Local notification flutter

can anyone show me with code that how can I schedule the notification in flutter using local notification plugin.任何人都可以向我展示如何使用本地通知插件在颤振中安排通知的代码。 Tried the example in git repository buy it doesn't work for me, although a normal notification is working but how can i schedule it for a specific time like a reminder?尝试了 git 存储库中的示例,购买它对我不起作用,尽管正常通知正在工作,但我如何将其安排在特定时间,例如提醒?

From the plugin sample code if you wanna schedule a notification you have to use a code like that:插件示例代码中,如果你想安排一个通知,你必须使用这样的代码:

/// 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);
  }

The part you must focus is that:您必须关注的部分是:

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

I suggest you to clone the plugin repo and try its example if you are not sure about the native projects setup to do in order to have your notifications to be shown.我建议您克隆插件存储库并尝试它的示例,如果您不确定要设置的本机项目以便显示您的通知。

/// IMPORTANT: running the following code on its own won't work as there is setup required for each platform head project. /// 重要提示:单独运行以下代码将不起作用,因为每个平台头项目都需要进行设置。

/// Please download the complete example app from the GitHub repository where all the setup has been done /// 请从已完成所有设置的 GitHub 存储库下载完整的示例应用程序

const AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails('repeating channel id','repeating channel name', 'repeating description');
const NotificationDetails platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.periodicallyShow(0, 'repeating title', 'repeating body', RepeatInterval.everyMinute, platformChannelSpecifics, androidAllowWhileIdle: true);

you can use periodicallyShow flutter_local_notifications您可以定期使用Show flutter_local_notifications

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM