Issue in Displaying Notification with awesome_notifications in Flutter
Asked Answered
N

4

6

I am new to flutter.I have started to create a reminder app.I am trying to call a push notification on android alarm call back.I am using awesome_notifications. On call back I am calling _ringAlarm().I have pasted it below. It says D/NotificationSender( 5192): Notification created, but nothing shows on screen.

This exception was thrown while running:

W/System.err( 5192): java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=basic_channel shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x11 color=0xff9d50dd vis=UNKNOWN(2))

Future _ringAlarm() async {

  AwesomeNotifications().initialize(
    'resource://drawable/logo.png',
    [
        NotificationChannel(
            channelKey: 'basic_channel',
            channelName: 'Basic notifications',
            channelDescription: 'Notification channel for basic tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white
        )
    ]
  );

  AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
    if (!isAllowed) {
      AwesomeNotifications().requestPermissionToSendNotifications();
    }
  });

  AwesomeNotifications().createNotification(
    content: NotificationContent(
        id: 10,
        channelKey: 'basic_channel',
        title: 'Simple Notification',
        body: 'Simple body'
    )
  );

}
Nickola answered 23/10, 2020 at 11:26 Comment(0)
E
10

That means that you had some problems with your icon to solve this problem you have to add an icon under "[project]/android/app/src/main/res/drawable/" named "logo.png". drawable position image

When initializing you must insert only the name without the extension like this

AwesomeNotifications().initialize(
    'resource://drawable/logo',
    [
        NotificationChannel(
            channelKey: 'basic_channel',
            channelName: 'Basic notifications',
            channelDescription: 'Notification channel for basic tests',
            defaultColor: Color(0xFF9D50DD),
            ledColor: Colors.white
        )
    ]
  );

Right now the only method available is via resource

Earp answered 2/11, 2020 at 7:15 Comment(0)
P
3

On top of Workflop's answer, I also had to uninstall the app from my phone, then run the installation again on Android Studio.

I had the same issue when adding an image to my app. It seems to be related to the debug cache.

I also found out that the source image is extremely restricted, but somehow this is not explained in the Awesome Notifications repo. Apparently, images must be 120x120 resolution at max and contain only simple graphics, not including pasted images. It only worked for me with text and vectorial graphics.

Pavkovic answered 21/4, 2021 at 15:48 Comment(0)
W
1

On top of all the answers I would also add something that is a must to actually see the icon.

in build.gradle file, make sure you have set shrinkResources false for the release/debug version you are testing, if its set to True, nothing from the above will help

Waves answered 26/3 at 23:39 Comment(0)
W
0

This worked for me:

minifyEnabled false
shrinkResources false
Weaken answered 7/9 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.