flutter - Flutter Local Notifications 如何在顶部菜单上显示图标
问题描述
嗨,我的通知工作正常,它也给手机振动,但图标和通知没有显示在屏幕上,你必须向下滑动,你可以在上面的菜单中看到它。我怎样才能在屏幕上显示
手机上的菜单是
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
@override
void initState() {
super.initState();
_advertService.showBanner();
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final android = AndroidInitializationSettings('@mipmap/ic_launcher');
final iOS = IOSInitializationSettings();
final initSettings = InitializationSettings(android, iOS);
flutterLocalNotificationsPlugin.initialize(initSettings,
onSelectNotification: _onSelectNotification);
}
Future<void> _onSelectNotification(String json) async {
final obj = jsonDecode(json);
if (obj['isSuccess']) {
OpenFile.open(obj['filePath']);
} else {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Error'),
content: Text('${obj['error']}'),
),
);
}
}
Future<void> _showNotification(Map<String, dynamic> downloadStatus) async {
final android = AndroidNotificationDetails(
'channel id', 'channel name', 'channel description',
priority: Priority.High, importance: Importance.Max);
final iOS = IOSNotificationDetails();
final platform = NotificationDetails(android, iOS);
final json = jsonEncode(downloadStatus);
final isSuccess = downloadStatus['isSuccess'];
await flutterLocalNotificationsPlugin.show(
0, // notification id
isSuccess ? 'Okay' : 'Fail',
isSuccess
? 'Downloaded'
: 'Failed',
platform,
payload: json);
}
解决方案
首先,您将设置 Flutter Launcher Icons
设置配置文件
dev_dependencies: flutter_launcher_icons: "^0.7.3" flutter_icons: android: "launcher_icon" ios: true image_path: "assets/icon/icon.png"
如果您将配置文件命名为 flutter_launcher_icons.yaml 或 pubspec.yaml 以外的名称,则需要在运行包时指定文件名。
注意:如果您不使用现有的 pubspec.yaml,请确保您的配置文件位于与其相同的目录中。
运行包
flutter pub get flutter pub run flutter_launcher_icons:main
使用这个插件
推荐阅读
- bash - 如何在 Makefile 中使用 lsof
- c# - 将带有 2 个简单 svg-s 的 html 转换为 pdf 文件 - 在 pdf 中仅显示一个 svg
- python - 如何确保 mypy 用户输入在一组文字中
- pimcore - 如何将 pimcore 从 6.8 升级到 6.9?
- python - 是否可以使用 Keras 屏蔽层屏蔽单个单元格?
- java - Bytebuddy - 代理私有注解方法
- html - 没有富文本的单行浏览器记事本
- sql - 参数数据类型 varchar 对 AT TIME ZONE 函数的参数 1 无效
- echarts - 如何划分史密斯圆图的 X 轴
- c# - c# 忽略字符串中的 {