Closed wfybiz closed 4 years ago
Were you able to get this working from a background message? If so, how?
ya I fixed it by registering the badge plugin with the FCM plugin. You can see the approach below:
package com.example.io;
import io.flutter.plugin.common.PluginRegistry import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin import fr.g123k.flutterappbadger.FlutterAppBadgerPlugin
object FirebaseCloudMessagingPluginRegistrant { fun registerWith(registry: PluginRegistry?) { if (alreadyRegisteredWith(registry)) { return } FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); FlutterLocalNotificationsPlugin.registerWith(registry?.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin")); FlutterAppBadgerPlugin.registerWith(registry?.registrarFor("fr.g123k.flutterappbadger.FlutterAppBadgerPlugin")); }
private fun alreadyRegisteredWith(registry: PluginRegistry?): Boolean {
val key: String? = FirebaseCloudMessagingPluginRegistrant::class.java.canonicalName
if (registry?.hasPlugin(key)!!) {
return true
}
registry.registrarFor(key)
return false
}
}
Thanks, I just figured this out and was about to comment the same. I appreciate the response!
I tried it in background message like this but throws errors {Unhandled Exception: MissingPluginException(No implementation found for method updateBadgeCount on channel g123k/flutter_app_badger)}
Future myBackgroundMessageHandler(Map<String, dynamic> message) async {
FlutterAppBadger.updateBadgeCount(1);
}
But works perfectly in here. Gives problem only in background message function
Widget build(BuildContext context) { _firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { FlutterAppBadger.updateBadgeCount(1); },); }