I am using awesome_notifications as my notification plugin; however, I get the error "Bad state: Stream has already been listened to."
whenever I call notifInitialize() in initState(). This happens every time I hot reload the application from fresh.
@override
void initState() {
notifInitialize();
super.initState();
}
This is how I am writing my function. Is there something wrong with how I set up my listeners?
void notifInitialize() {
notificationIcon = true;
AwesomeNotifications().initialize(
// set the icon to null if you want to use the default app icon
'resource://drawable/app_icon',
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Colors.teal,
importance: NotificationImportance.High,
channelShowBadge: true,
),
NotificationChannel(
channelKey: 'scheduled_channel',
channelName: 'Scheduled Notifications',
channelDescription: 'Scheduled Description',
defaultColor: Colors.teal,
locked: true,
importance: NotificationImportance.High,
),
],
);
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
AwesomeNotifications().createdStream.listen((notification) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Notification Created on ${notification.channelKey}',
)));
});
AwesomeNotifications().actionStream.listen((notification) {
if (notification.channelKey == 'basic_channel' && Platform.isIOS) {
AwesomeNotifications().getGlobalBadgeCounter().then((value) {
print(value);
AwesomeNotifications().setGlobalBadgeCounter(value - 1);
print(value);
});
}
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => ValidateService()),
//(route) => route.isFirst);
(route) => false);
});
}```