6

I'm new in flutter so please don't kill me if my question is easy.

notification icon doesn't show like this

enter image description here

I put in this path

\android\app\src\main\res\drawable

here is my code for icon:

 final settingsAndroid = AndroidInitializationSettings('app_icon');
 final settingsIOS = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotification(payload));
 final settingsIOSgeneral = IOSInitializationSettings(onDidReceiveLocalNotification: (id, title, body, payload) => onSelectNotificationgeneral(payload));
 notifications.initialize(InitializationSettings(settingsAndroid, settingsIOS), onSelectNotification: onSelectNotification);

Can Any one help me please how can I preview my icon in notification ?

Ichigo Kurosaki
  • 3,670
  • 8
  • 37
  • 55
Eman Fateen
  • 661
  • 2
  • 7
  • 13
  • Looks like a proguard issue, see this https://stackoverflow.com/a/61303224/8912043 – Taz Feb 07 '22 at 07:28

4 Answers4

10

I did the following and it worked for me:

  1. Create a transparent and white notification icon (you can use the following tool: AndroidAssetStudio )

Download the zip folder, unzip and you'll see it contains a res folder with different drawable folders. Copy and paste the contents of the res folder in "android\app\src\main\res" path

Folder Structure

  1. Then open the AndroidManifest.xml file and add the following lines to it:

ic_stat_calendar_today is the name of my notification icon. And each of the drawable folders that have been pasted contain a different size of icon with the same name.

Android Manifest

  1. If you want to change the color of the icon then check the above image. Add the metadata tag after the notification icon tag

  2. Go to "android\app\src\main\res\values" and add a colors.xml file

colors.xml

<color name="colorAccent">#00FF00</color>

I have shared this answer in the following Github chain as well- Solution.

user2549980
  • 493
  • 6
  • 18
3

This could be because the icon image is not transparent -- Try the notification icon generated from this tool. Also check this question Android Push Notifications: Icon not displaying in notification, white square shown instead

Sandeep Chayapathi
  • 1,440
  • 2
  • 13
  • 31
1

generate a transparent icon and then set the color in AndroidNotificationDetails parameter

kk.
  • 3,288
  • 11
  • 33
  • 60
Zahra Jamshidi
  • 515
  • 5
  • 8
0

You must do three things;

1.follow @user2549980's answer and do samethins step by step but in colors.xml file, you must write encoding="utf-8" with uppercase format, like;

(your notification icon must be copied mipmap folders with same sizes, and you must add that icon name to your AndroidManifest.xml, and it must be transparent icon.)

2.Step; in your local notification init function,

 _notificationPlugin=FlutterLocalNotificationsPlugin();

await _notificationPlugin.initialize(
    const InitializationSettings(
        android: AndroidInitializationSettings('@mipmap/notification_icon'),
        iOS: IOSInitializationSettings()
    ),
  onSelectNotification: (payload) async{

  
  },
);

you must change this line @mipmap/icon_name with your icon name.

and I am writing this comment because, this step can be missed easily so, don't forget this step.

leylekseven
  • 412
  • 4
  • 11