Hi I want create app with GetX and awesome_notifications, But after i click on button this error is show: how can fix this? please help.
W/Android: Awesome Notifications: Channel model 'basic_channel' was not found (ChannelManager:88) E/Android: Awesome Notifications: Channel 'basic_channel' does not exist (NotificationBuilder:58)
this is my controller for the app:
class HomeScreenController extends GetxController {
RxString verb = "".obs;
RxBool check = false.obs;
@override
void onInit() {
// TODO: implement onInit
super.onInit();
checkOffOn();
random();
}
static void initializeNotificationService() {
AwesomeNotifications().initialize("assets/images/notification.png", [
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic Notifications',
defaultColor: Colors.teal,
importance: NotificationImportance.Max,
channelShowBadge: true,
channelDescription: 'show positive energy every day',
enableVibration: true,
enableLights: true,
//playSound: true,
//soundSource: ""
),
]);
}
void random() {
final random = Random();
verb.value = EnergyList[random.nextInt(EnergyList.length)].sentences;
}
void checkOffOn() {
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
check.value = false;
} else {
check.value = true;
}
});
}
void notification() {
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
Get.defaultDialog(
title: "اعلان ها",
middleText: 'به برنامه اجازه نمایش اعلان را می دهید؟',
backgroundColor: Colors.greenAccent,
textConfirm: 'اجازه می دم',
cancelTextColor: Colors.black,
confirmTextColor: Colors.black,
textCancel: 'بی خیالش',
buttonColor: Colors.yellowAccent,
titleStyle: const TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Colors.black,
height: 2),
middleTextStyle: const TextStyle(
fontSize: 25,
color: Colors.black,
),
onConfirm: () {
check.value = true;
AwesomeNotifications().requestPermissionToSendNotifications();
Get.back();
},
);
} else {
Get.defaultDialog(
title: "اعلان ها",
middleText: 'آیا می خواهید اعلان ها متوقف شود؟',
backgroundColor: Colors.greenAccent,
textConfirm: 'آره بشه',
cancelTextColor: Colors.black,
confirmTextColor: Colors.black,
textCancel: 'نه بذار باشه',
buttonColor: Colors.yellowAccent,
titleStyle: const TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Colors.black,
height: 2),
middleTextStyle: const TextStyle(
fontSize: 25,
color: Colors.black,
),
onConfirm: () {
check.value = false;
AwesomeNotifications()
.cancelNotificationsByChannelKey('basic_channel');
Get.back();
},
);
}
});
}
Future<void> createNotification() async {
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: DateTime.now().microsecond,
channelKey: 'basic_channel',
title: "پیام روز",
body: "تست",
backgroundColor: Colors.tealAccent,
color: Colors.black,
displayOnForeground: true,
wakeUpScreen: true,
),
);
}
}
and this is my home screen button code:
ElevatedButton(
onPressed: () {
controller.createNotification();
},
child: const Text('تست'),
),