当我从 Firebase Cloud Messaging 发送通知时,通知徽章会显示在应用程序图标上,但没有代码可将其删除。
通知的数量并不重要,所以我不需要任何通知计数器或其他什么,所以我需要做的就是在打开应用程序时清除通知徽章。
如何在不重写整个通知代码的情况下完成此任务(我几乎无法正常工作)?
这是代码:
_fcm.getToken().then((token) {
print("The token is: " + token);
setState(() {
tokenSave = token;
});
});
_fcm.requestPermission(
sound: true,
badge: true,
alert: true,
provisional: false,
);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification notification = message.notification;
AndroidNotification android = message.notification?.android;
if (notification != null && android != null) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channel.description,
color: Colors.blue,
playSound: true,
icon: null,
),
),
);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("onMessageOpenedApp event");
RemoteNotification …Run Code Online (Sandbox Code Playgroud) push-notification ios firebase flutter firebase-cloud-messaging
现在,我的应用程序可以刷新的唯一方法(它是一个新闻应用程序,因此需要不断刷新)有两种方法:1)通过向上滚动刷新或2)从后台杀死应用程序后重新启动应用程序。
我想要做到这一点,以便当用户刚刚返回应用程序时(假设我正在使用我的应用程序,然后我去微信发送文本,然后我回来),应用程序就会刷新。
这是刷新滚动代码。
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
new GlobalKey<RefreshIndicatorState>();
Run Code Online (Sandbox Code Playgroud)
然后它调用这个函数:
Future<void> _refresh() async {
print("Refreshed");
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(),
),
).then((value) => null);
}
Run Code Online (Sandbox Code Playgroud)
我应该做什么来实现我所需要的?
有没有办法检查某人是否“返回”我的应用程序?然后我就可以调用该函数了。