Flutter Local Notifications and Cloud Firestore Queries in the BACKGROUND
––– views
•
2 mins
9 May 2021
flutter_local_notifications: cloud_store: firebase_messaging:
package <com.your.application> import android.util.Log import io.flutter.plugin.common.PluginRegistry import io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin class CloudFirestorePluginRegistrant { companion object { fun registerWith(registry: PluginRegistry){ Log.d("CloudFirestore", "registerWith"); if(alreadyRegisteredWith(registry)) { Log.d("Already Registered",""); return } try { CloudFirestorePlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin")) } catch (e: Exception) { Log.d("CloudFirestore", e.toString());} Log.d("Plugin Registered",""); } private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean { val key = CloudFirestorePluginRegistrant::class.java.canonicalName if (registry.hasPlugin(key)) { return true } registry.registrarFor(key) return false } } }
package <com.your.application> import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import com.your.application.CloudFirestorePluginRegistrant class Application : FlutterApplication(), PluginRegistry.PluginRegistrantCallback { override fun onCreate() { super.onCreate() } override fun registerWith(registry: PluginRegistry?) { if (registry != null) { CloudFirestorePluginRegistrant.registerWith(registry) }} }
onBackgroundMessage: _onMyBackGroundMessage; _onMybackGroundMessage(Map<String,dynamic> message){ firestore.instance.collection(message['data'['userName']) .document(notfication).set({name:['data']['userName]}); }