Flutter 本地通知图标未显示 [英] Flutter local notifications Icon not showing
问题描述
我遇到了一个很常见的问题,但我看到的任何解决方案都没有帮助我.所以,我正在尝试显示本地通知.
I am facing a problem that is very common, but no solution I saw helped me. So, I'm trying to show local notifications.
除了图标外,一切正常.按照包的文档,我向可绘制对象添加了一个图标,但它不起作用.
Everything works except the icon. Following the package's documentation, I added an icon to the drawable, but it doesn't work.
这是我的文件夹结构和我想显示的图像
Here is the structure of my folder and the image I want to show
这是我的初始化代码
我尝试了很多东西.我创建了透明的图标(使用 https://romannurik.github.io/AndroidAssetStudio/)和添加到可绘制对象中,添加了第一个图像中的 PNG.
I tried many things. I created icons with transparency (using https://romannurik.github.io/AndroidAssetStudio/) and added to the drawable, added the PNG as in the first image.
它仅在我将标准图标复制到可绘制对象(即 Flutter 徽标)时才有效.
It only works when I copy the standard icon to the drawable, which is the Flutter logo.
推荐答案
这个包的文档不是很清楚.您需要将 app_icon
名称更改为 res/drawable
文件夹中的图标文件,才能使自定义图标生效.在您的情况下,一个示例可以是 ic_launcher.png
.代码中用于更改的特定行是:
Documentation of this package is not so clear about it. You need to change name app_icon
to the icon file from your res/drawable
folder to have an effect of your custom icon. In your case one example can be ic_launcher.png
. Specific line in your code for a change is:
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('app_icon');
注意:如果您的通知图标变灰,请点击此链接寻求解决方案:https://stackoverflow.com/a/63746521/15236786
Note: If your notification icon gets grey then follow this link for solution: https://stackoverflow.com/a/63746521/15236786
这篇关于Flutter 本地通知图标未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!