任何人都可以通过代码向我展示如何使用本地通知插件在通知中安排通知。 尝试了git存储库中的示例购买对我来说不起作用,尽管正常的通知正在起作用,但是我如何像提醒一样在特定时间安排它?
答案 0 :(得分:2)
在plugin sample code中,如果您想安排通知,则必须使用如下代码:
/// 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存储库下载完整的示例应用程序,其中所有 设置已经完成
答案 1 :(得分:-1)
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);
您可以定期使用显示flutter_local_notifications