J'ai essayé de mettre en œuvre la messagerie en nuage de Firebase avec Flutter, et j'étais succès jusqu'à ce que j'utilise le plugin "Notification locale" pour montrer la notification
Ma notification fonctionne bien au premier plan, mais sur l'arrière-plan, cette erreur montre cette erreur:
[ERREUR: PLUTTER/UI/UI_DART_STATE.CC (157)]] Non gourde Exception: mangepluginexception (aucune implémentation trouvée pour la méthode Afficher sur Channel Dexterous.com/flutter/Local_notifications)
J'utilise Firebase Cloud Messaging 6.0.9, Notification locale 1.2.0 + 4 et dernier flotteur
Voici mon code: NotificationHandler
import 'package:flutter_local_notifications/flutter_local_notifications.Dart';
class NotificationHandler{
static final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // make it a static field of the class
static void initNotification()
{
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
static Future onSelectNotification(String payload) async {
if (payload != null) {
print('notification payload: ' + payload);
}
}
static Future onDidReceiveLocalNotification(int id, String title, String body, String payload) {
print(title+" "+body);
}
}
Méthode de manifestation
static void showNotification(data, data2) async {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'dexterous.com.flutter.local_notifications', 'your channel name', 'your channel description',
importance: Importance.Max,
priority: Priority.High);
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await NotificationHandler.flutterLocalNotificationsPlugin
.show(
0,
data,
data2,
platformChannelSpecifics,
payload: 'Custom_Sound',
);
}
Pour Kotlin: Application.kt
package your.package.name
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.view.FlutterMain
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
FlutterMain.startInitialization(this)
}
override fun registerWith(registry: PluginRegistry?) {
if (!registry!!.hasPlugin("io.flutter.plugins.firebasemessaging")) {
FirebaseMessagingPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
if (!registry!!.hasPlugin("com.dexterous.flutterlocalnotifications")) {
FlutterLocalNotificationsPlugin.registerWith(registry!!.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));
}
}
}