[英]Local notification flutter
任何人都可以向我展示如何使用本地通知插件在顫振中安排通知的代碼。 嘗試了 git 存儲庫中的示例,購買它對我不起作用,盡管正常通知正在工作,但我如何將其安排在特定時間,例如提醒?
從插件示例代碼中,如果你想安排一個通知,你必須使用這樣的代碼:
/// 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 存儲庫下載完整的示例應用程序
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.