简体   繁体   English

Flutter 本地通知图标未显示

[英]Flutter local notification icon not showing

I have an application using Package Flutter Local Notification for showing notifications.我有一个应用程序使用Package Flutter 本地通知来显示通知。 Everything is fine, I can show the notification.一切都很好,我可以显示通知。 The problem is my image as icon notification does not show, only full color of my image.问题是我的图像作为图标通知没有显示,只有我的图像的全彩色。

What I have done:我做了什么:

  • Setting InitLocalNotification like documentation像文档一样设置 InitLocalNotification

     void initLocalNotification() async { _androidInitializationSettings = AndroidInitializationSettings('app_icon'); _iosInitializationSettings = IOSInitializationSettings( onDidReceiveLocalNotification: _onDidReceiveLocalNotification, ); _initializationSettings = InitializationSettings( _androidInitializationSettings, _iosInitializationSettings, ); await _flutterLocalNotificationsPlugin.initialize( _initializationSettings, onSelectNotification: _onSelectNotification, ); }
  • Set structure folder like documentation设置结构文件夹,如文档

  • Resize my logo like logo in documentation (Width: 36px, Height: 36px, Background: Transparant, Extension: .png)调整我的徽标大小,如文档中的徽标(宽度:36 像素,高度:36 像素,背景:透明,扩展名:.png)

    在此处输入图像描述

Even though I have done the above method, my image icon is not showing, only the color.即使我已经完成了上述方法,我的图像图标也没有显示,只有颜色。

Result (does not work)结果(不起作用)

After that, I tried to change my image with image from documentation, and that is working.之后,我尝试使用文档中的图像更改我的图像,这很有效。 Image icon is shown in notification.图像图标显示在通知中。

Image from documentation图片来自文档

在此处输入图像描述

Result (works)结果(作品)

Did I missed something?我错过了什么吗?

If your icon displays as rectangle on release build and you are sure that your icon matches notification icon guidelines then you should try to disable shrinking resources in build.gradle:如果您的图标在发布版本中显示为矩形,并且您确定您的图标符合通知图标指南,那么您应该尝试在 build.gradle 中禁用收缩资源:

buildTypes {
    release {
        signingConfig signingConfigs.release
        shrinkResources false
    }
}
 NotificationDetails(
        android: AndroidNotificationDetails(
          channel.id,
          channel.name,
          channelDescription: channel.description,
          icon: '@mipmap/ic_notification_no_bg',
          styleInformation: BigTextStyleInformation(''),
        ),
      ));

You need to provide a icon which does not have any background in AndroidNotificationDetails so App will pick this icon for Android version 11 for other versions it will pick default launcher Icon您需要在 AndroidNotificationDetails 中提供一个没有任何背景的图标,因此应用程序将为Android 版本 11选择此图标,其他版本将选择默认启动器图标

For anyone looking at this.对于任何看到这个的人。 The problem here comes from the shape of the icon.这里的问题来自图标的形状。 In most android version the notification icon is just a shape filled with a color (such as the F of flutter).在大多数 android 版本中,通知图标只是一个填充了颜色的形状(如颤动的 F)。 A rectangular icon with no transparency will be a rectangle filled with a color.没有透明度的矩形图标将是一个填充有颜色的矩形。

Some constructor, such as Samsung, show the actual image in some of their software version.一些建设者,如三星,在他们的一些软件版本中显示实际图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM