The question is I want to receive FCM notification from different view because I have notification bell icon which is updated whenever the notification is received.I have Profile View, Landing View, Dashboard View and others. So I have badge in there which needs update. However, I cannot receive the broadcast either using Stream or Notifier. The only option I have is to add a bulky line to each of these pages. i.e
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
setState(() {
counter++;
});
_newNotification = true;
_showNotificationWithDefaultSound(message.toString());
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
setState(() {
counter++;
});
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
setState(() {
counter++;
});
print("onResume: $message");
},
);
And also I need to add couple of functions to get it working.So my question is how do you receive it with the minimum possible lines.As I have tried Stream broadcast which only works for single page and I cant listen it from another page.Anyone if they had this issue please share.All in the internet I am getting this solution and which is not applicable for me .
void initState() {
super.initState();
print("Creating a sample stream...");
Stream<String> stream = new Stream.fromFuture(getData());
print("Created the stream");
stream.listen((data) {
print("DataReceived: "+data);
}, onDone: () {
print("Task Done");
}, onError: (error) {
print("Some Error");
});
print("code controller is here");
}