I am trying to add notification to my flutter project when i run the project show me this error:
E/Android: Awesome Notifications: Invalid notification (no valid small icon): Notification(pri=2 contentView=com.example.test/0x1090085 vibrate=null sound=content://settings/system/notification_sound tick defaults=0x0 flags=0x11 color=0xff000000 vis=PRIVATE) (NotificationThread:58)
mainscreen.dart
import 'package:flutter/material.dart';
import 'package:test/page/notification_service.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key:key);
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
@override
void initState(){
// TODO: implement initState
super.initState();
NotificationService().requestPermission();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: (){
NotificationService().showNotification(
1,
'main_channel',
'Test title',
'Test body',
);
},
child: Container(
height: 30,
width: 70,
color: Colors.blue,
child: Text(
"SHOW NOTIFICATION"
),
),
) ,
GestureDetector(
onTap: () {
NotificationService().showScheduledNotification(
1,
'main_channel',
'Test title',
'Test body',
5,
);
},
child: Container(
height: 30,
width: 70,
color: Colors.red,
child: Text(
"SHOW NOTIFICATION2"
),
),
),
],
),
),
);
}
}
notification_service.dart
import 'package:awesome_notifications/awesome_notifications.dart';
class NotificationService{
static final NotificationService _notificationService = NotificationService._internal();
factory NotificationService(){
return _notificationService;
}
NotificationService._internal();
Future<void> initAwesomeNotification()async{
AwesomeNotifications().initialize(
'resource://drawable/ic_applogo',
[
NotificationChannel(
channelKey: 'main_channel',
channelName: 'main_channel',
channelDescription: 'main_channel notifications',
enableLights: true,
importance: NotificationImportance.Max,
)
],
);
}
Future<void> requestPermission() async{
AwesomeNotifications().isNotificationAllowed().then((allowed){
if(!allowed){
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
}
Future<void> showNotification(int id,String channelKey,String title,String body) async{
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: channelKey,
title: title,
body: body,
),
);
}
Future<void> showScheduledNotification(int id, String channelKey, String title, String body, int interval) async {
String localTZ = await AwesomeNotifications().getLocalTimeZoneIdentifier();
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: channelKey,
title: title,
body: body,
),
schedule: NotificationInterval(
interval: interval,
timeZone: localTZ,
repeats: false,
)
);
}
}
CodePudding user response:
The logo might be causing the problem so:
Try to replace this: 'resource://drawable/ic_applogo',
with the following null,