MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)
Asked Answered
K

4

8

I've try implement Firebase Cloud Messaging with Flutter, and i was success until i use 'Local Notification' plugin for show notification

My notification work fine on foreground, but on background this show this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)

I use Firebase Cloud Messaging 6.0.9, Local Notification 1.2.0+4 and latest Flutter

Here is my 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);
  }

}

ShowNotification method

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',
      );

  }
Krasnoff answered 1/3, 2020 at 3:23 Comment(2)
Follow these steps 1) Use flutter clean command 2) Uninstall previous app 3) Re install the appFaiyum
Thank you, problem is solved. This step is useless :(Krasnoff
K
17

I have found solution, that why in platform side we don't register for outside plugin

Add in your FCMPluginRegistrant.java like

public final  class FirebaseCloudMessagingPluginRegistrant {

    public static void registerWith(PluginRegistry registry) {

        if (alreadyRegisteredWith(registry)) {
            return;
        }
        FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        FlutterLocalNotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));


    }




    private static boolean alreadyRegisteredWith(PluginRegistry registry) {
        final String key = FirebaseCloudMessagingPluginRegistrant.class.getCanonicalName();
        if (registry.hasPlugin(key)) {
            return true;
        }
        registry.registrarFor(key);
        return false;
    }
}

And call it on Application.java

  @Override
    public void registerWith(PluginRegistry registry) {



        FirebaseCloudMessagingPluginRegistrant.registerWith(registry);

    }
Krasnoff answered 7/3, 2020 at 11:15 Comment(2)
This works for me. Haven't checked if similar workaround needed on other platforms. import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPluginBushhammer
Also import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin; in first piece of code above. It worked for me.Alleman
M
6

For 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"));
        }
    }
}
Mariande answered 17/5, 2020 at 6:7 Comment(1)
This does not seem to work for me #62821372Wordy
S
1

I just uninstall the app first, reinstall it again and it solves my problem.

Scorekeeper answered 11/1, 2022 at 9:2 Comment(0)
S
0

I had same problem when i use result.notImplemented in my native part of my hybrid application. Everything was solved when i replaced this method to result.success(0)

Superorder answered 30/12, 2020 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.