As per flutter package I implemented code on my project but it threw exception while making build, "Notification channel 'call_channel' does not exist., n.a.a.k.f.a:". I don't understand why it's happen?
Here is my code.
WidgetsFlutterBinding.ensureInitialized();
await AwesomeNotifications().initialize(
'resource://drawable/ic_launcher',
[
NotificationChannel(
channelGroupKey: 'category_tests',
channelKey: 'call_channel',
channelName: 'Calls Channel',
channelDescription: 'Channel with call ringtone',
defaultColor: Color(0xFF9D50DD),
importance: NotificationImportance.Max,
ledColor: Colors.white,
channelShowBadge: true,
locked: true,
defaultRingtoneType: DefaultRingtoneType.Ringtone),
],
channelGroups: [
NotificationChannelGroup(
channelGroupkey: 'category_tests',
channelGroupName: 'Category tests',
)
],
debug: true);
await Firebase.initializeApp();
CodePudding user response:
You have to make sure that channelKey has same name between NotifcationChannel
and createNotification
Function.
Below is setup notification
AwesomeNotifications().initialize(
// set the icon to null if you want to use the default app icon
null,
[
NotificationChannel(
channelGroupKey: 'basic_channel_group',
channelKey: 'call_channel', /* same name */
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white)
],
// Channel groups are only visual and are not required
channelGroups: [
NotificationChannelGroup(
channelGroupkey: 'basic_channel_group',
channelGroupName: 'Basic group')
],
debug: true);
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
// This is just a basic example. For real apps, you must show some
// friendly dialog box before call the request method.
// This is very important to not harm the user experience
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
////Notification Listener
AwesomeNotifications()
.actionStream
.listen((ReceivedNotification receivedNotification) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => BottomNavBar()),
(Route<dynamic> route) => false,
);
});
Called createNotification function.
Notification is display when this method is called.
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'call_channel', /* same name */
title: 'SMS Alert (${policy?.policyName})',
body: msg ?? ""));