问题是我想从其他视图接收FCM通知,因为我有通知铃图标,该图标在收到通知时会更新。我有配置文件视图,着陆视图,仪表板视图等。所以我在那里有需要更新的徽章。但是,我无法使用Stream或Notifier接收广播。我唯一的选择是在每个页面中添加一个大行。即
_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");
},
);
我还需要添加几个函数来使其正常工作。所以我的问题是如何以最少的行数接收它?因为我尝试了仅适用于单页的流广播并且无法从中收听
所有人都在互联网上,我正在获得此解决方案,但不适用于我。 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");
}