这就是我在 flutter 中使用 Awesome notifications 创建通知的方式
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1,
channelKey: 'basic_channel',
title: "You spent some money?",
body:
"We think, ₹ ${jsonObject['amount']} that was ${jsonObject['type']} to ${jsonObject['vendor']} belongs to this category: ${jsonObject['category']}",
actionType: ActionType.Default),
actionButtons: [
NotificationActionButton(
key: 'Approve',
label: 'Approve',
),
NotificationActionButton(
key: 'Edit',
label: 'Edit',
)
],
);
我想为批准和编辑选项添加不同的功能。执行此操作的确切语法是什么?
try {
var response = await http.get(Uri.parse(url));
if (Platform.isAndroid) {
await Permission.storage.request();
}
var status = await Permission.storage.status;
if (!status.isGranted) {
await Permission.storage.request();
}
if (response.statusCode == 200) {
String fileName = 'certificate_$certificateNumber.pdf';
const downloadsFolderPath = '/storage/emulated/0/Download/';
Directory dir = Directory(downloadsFolderPath);
File file = File('${dir.path}/$fileName');
OpenFile.open(file.path);
AwesomeNotifications().createNotification(
actionButtons: [
NotificationActionButton(
key: 'OPEN',
label: 'Open',
),
],
content: NotificationContent(
payload: {'PDF_Downloader': dir.path, 'file': fileName},
id: 1,
channelKey: "PDF_Downloader",
title: "Certificate Downloaded",
body: "PDF has been downloaded successfully in Download Folder",
),
);
await file.writeAsBytes(response.bodyBytes);
String date = DateTime.now().toString();
setState(() {
verificationDate = date;
});
这是下载 PDF 文件并显示 PDF 已成功下载的通知并提供打开它的选项的示例 所以,我已将有效负载传递给通知
在您的情况下,您必须提供 Channel Key,并且必须为您的特定功能创建一个函数并替换
enter code here
dir.path
我希望它会起作用。