The error you get is not caused by _notificationsActionStreamSubscription.
If you read carefully it says
Stream has already been listened to
That means that probably AwesomeNotifications().actionStream can only handle one listener at a time.
_notificationsActionStreamSubscription.cancel() doesn't seem to work, it is possible that AwesomeNotifications().actionStream doesn't know that the stream listener has been closed.
Every time the page get pushed, it is rebuilt, and AwesomeNotifications() throw an error becouse it thinks that you are attacching a second listener.
So I came with this solution: Move the notificationsActionStreamSubscription to a widget which is parent to HomeView.
Create the instance right there in the parent, and then attach it to the actionStream.
Every time you call Navigator.pushReplacement send it as a parameter.
HomeView: (I made it a statefullwidget)
class HomeView extends StatefulWidget {
final StreamSubscription<ReceivedAction> notificationsActionStreamSubscription;
const HomeView({Key key, @required this.notificationsActionStreamSubscription}) : super(key: key);
@override
_HomeViewState createState() => _HomeViewState();
}
class _HomeViewState extends State<HomeView> {
//You can access with widget.notificationsActionStreamSubscription
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('HomeView '),
),
body: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [],
)
],
),
),
);
}
}
In your parent widget (I suppose it is a statefull widget):
StreamSubscription<ReceivedAction> notificationsActionStreamSubscription;
@override
void initState() {
super.initState();
notificationsActionStreamSubscription =
AwesomeNotifications().actionStream.listen((receivedNotification) {
print(
"user tapped on notification " + receivedNotification.id.toString());
});
}
And every time you push the HomeView:
Navigator.of(context).popUntil((route) => route.isFirst);
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => HomeView(notificationsActionStreamSubscription:
notificationsActionStreamSubscription)));
By doing so, notificationsActionStreamSubscription will not be rebuilt and attached to AwesomeNotifications().actionStream every time you push the HomeView.