Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

firebase - MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)

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

  }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...