Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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) #477

Closed
curlyeto opened this issue Feb 11, 2020 · 5 comments

Comments

@curlyeto
Copy link

[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/flutter (23518): Arka plandan gelen mesaj {image-url: your_image_url, title: Your title, message: Your message}
E/flutter (23518): [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)
E/flutter (23518): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter (23518):
E/flutter (23518): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter (23518): #2 AndroidFlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:135:21)
E/flutter (23518): #3 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:93:13)
E/flutter (23518): #4 NotificationHandler.showNotification (package:newflutter/handler/notificationhandler.dart:79:43)
E/flutter (23518): #5 myBackgroundMessageHandler (package:newflutter/handler/notificationhandler.dart:18:25)
E/flutter (23518): #6 _fcmSetupBackgroundChannel. (package:firebase_messaging/firebase_messaging.dart:38:30)
E/flutter (23518): #7 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:409:55)
E/flutter (23518): #8 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:377:54)
E/flutter (23518): #9 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:200:33)
E/flutter (23518): #10 _invoke3. (dart:ui/hooks.dart:303:15)
E/flutter (23518): #11 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (23518): #12 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (23518): #13 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (23518): #14 _invoke3 (dart:ui/hooks.dart:302:10)
E/flutter (23518): #15 _dispatchPlatformMessage (dart:ui/hooks.dart:162:5)

CODE

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

Future<void> myBackgroundMessageHandler(Map<String, dynamic> message) {
  if (message.containsKey("data")) {
    // Handle data message
    final dynamic data = message['data'];
    print("Arka plandan gelen mesaj ${message['data'].toString()}");
    NotificationHandler.showNotification(message);
  }

  return Future<void>.value();
}


class NotificationHandler {


  FirebaseMessaging _fcm = FirebaseMessaging();

  static final NotificationHandler _singleton = NotificationHandler._internal();
  factory NotificationHandler() {// factory constructordan geriye deger return etmek için kullanılı
    return _singleton;
  }
  NotificationHandler._internal();
  BuildContext myContext;

  initializeFCMNotification(BuildContext context) async {
    myContext = context;

    var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
    var initializationSettingsIOS = IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    var initializationSettings = InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    await flutterLocalNotificationsPlugin.initialize(initializationSettings,onSelectNotification: onSelectNotification);



    _fcm.subscribeToTopic("cars");
    _fcm.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
        showNotification(message);
      },
      onBackgroundMessage: myBackgroundMessageHandler,
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
      },
    );
    _fcm.requestNotificationPermissions(
        const IosNotificationSettings(
            sound: true, badge: true, alert: true, provisional: true));
    _fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
      print("Settings registered: $settings");
    });
    _fcm.getToken().then((String token) {
    });
  }

 static void showNotification(Map<String, dynamic> message) async {
    var androidPlatformChannelSpecifics = AndroidNotificationDetails(
        'your channel id', 'your channel name', 'your channel description',
        importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
    var iOSPlatformChannelSpecifics = IOSNotificationDetails();
    var platformChannelSpecifics = NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(1, "message[1].toString()","message[3].toString()", platformChannelSpecifics,payload: 'Bildirime tıklanılınca aktarılan değer');
    //print('Deneme $message');
  }

  Future onDidReceiveLocalNotification(int id, String title, String body, String payload) {}

  Future onSelectNotification(String payload) {
    if(payload !=null){
      debugPrint('notification payload' +payload);
    }
  }
}
@MaikuB
Copy link
Owner

MaikuB commented Feb 11, 2020

Sorry but I can't understand what your issue is without a description. Could you please add more details?

@curlyeto
Copy link
Author

İssue:
[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)

@MaikuB
Copy link
Owner

MaikuB commented Feb 11, 2020

Whilst that is the error, what I'm asking for is for you to describe the scenarios the error occurs i.e. steps to reproduce

@curlyeto
Copy link
Author

**Firstly **
I want to backgroundmessagenotofication with local notification.
Secondly
https://pub.dev/packages/firebase_messaging STEP -> Optionally handle background messages 1.step İS ERROR
Thirdly
error solution find -> https://stackoverflow.com/a/59490722 and I applied my application
Finally
Then I wrote the code above.Run application and send notice postman onmessage function is run and I saw the notice.
But I closed application and send notice postman code.Program entered myBackgroundMessageHandler function but didn't run this line -> NotificationHandler.showNotification(message);

@MaikuB
Copy link
Owner

MaikuB commented Feb 11, 2020

This is something to ask on the firebase_messaging repo as I don't know what is required for background messaging to use other plugins and how it works. Looks like you already did this as well. In the past this requires developers to do more setup in their application. Might be the same in this case. With my own experience in background execution, I had to move declaring and creating the FlutterLocalNotificationsPlugin object inside the static method and call initialize etc after that. You might want to see if that helps you here as well.

Closing this since this relates to another plugin's functionality and not an issue with this plugin (also noted by another member of the community that had the same issue here)

@MaikuB MaikuB closed this as completed Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants