gpt4 book ai didi

Flutter:创建一个 pdf 文件,显示下载通知并在用户单击通知时打开它

转载 作者:行者123 更新时间:2023-12-05 02:33:42 26 4
gpt4 key购买 nike

我正在开发一个 flutter 应用程序。我在“下载”文件夹中创建一个 pdf 文件,在“下载”文件夹中创建文件后,使用“local_notification”插件显示通知“下载已完成”。

现在我想在用户点击通知时显示该 pdf。谁能指导我如何做到这一点?

下面是我的代码

final android = AndroidNotificationDetails('0', 'Adun Accounts',
channelDescription: 'channel description',
priority: Priority.high,
importance: Importance.max,
icon: '');
final iOS = IOSNotificationDetails();
final platform = NotificationDetails(android: android, iOS: iOS);

await flutterLocalNotificationsPlugin.show(
0, // notification id
fileName,
'Download complete.',
platform);

最佳答案

show() 有一个参数叫做 payload ,你可以在这里传递 pdf 文件的路径。在您的 pubspec.yaml 中添加插件 open_file。然后在 main.dart 中,添加以下代码

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

Future<void> initNotification() async {
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('notification_icon');
final IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings();
final MacOSInitializationSettings initializationSettingsMacOS =
MacOSInitializationSettings();
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
macOS: initializationSettingsMacOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String? payload) {
if (payload != null) OpenFile.open(payload);
});
}

注意:这个函数不应该在任何类中。

关于Flutter:创建一个 pdf 文件,显示下载通知并在用户单击通知时打开它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70902376/

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