gpt4 book ai didi

flutter - 本地通知抖动

转载 作者:IT王子 更新时间:2023-10-29 06:38:12 25 4
gpt4 key购买 nike

谁能告诉我如何使用本地通知插件在 flutter 中安排通知的代码。尝试了 git repository buy 中的示例,它对我不起作用,虽然正常通知有效但我如何安排它在特定时间提醒?

最佳答案

来自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));

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

/// 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

关于flutter - 本地通知抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54215211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com