title: Flutter Firebase Messaging is Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
body: <p>I am trying to use Firebase Messaging in a Flutter app. I follow all the instruction from the package. </p>
  
  <p>In my pubspec.yaml I have these packages:</p>
  
  <pre><code>dependencies:
    flutter:
      sdk: flutter
    ...
    firebase_messaging: ^5.1.5
    ...
  </code></pre>
  
  <p>My main.app is just it:</p>
  
  <pre><code>void main() {
    runApp(MyApp());
  }
  </code></pre>
  
  <p>MyApp is a StatefullWidget and inside the _MyAppState I have:</p>
  
  <pre><code>    FirebaseMessaging firebaseMessaging = FirebaseMessaging();
     @override
    void initState() {
      super.initState();
      NotificationHandler().initializeFcmNotification();
    }
  </code></pre>
  
  <p>All the code is inside whe notification_handler.dart (thanks to @HarishPenta):</p>
  
  <pre><code>...
  import 'package:firebase_messaging/firebase_messaging.dart';
  ...
  
  class NotificationHandler {
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
    FirebaseMessaging _fcm = FirebaseMessaging();
    StreamSubscription iosSubscription;
    static final NotificationHandler _singleton =
    new NotificationHandler._internal();
  
    factory NotificationHandler() {
      return _singleton;
    }
    NotificationHandler._internal();
  
    Future&lt;dynamic&gt; myBackgroundMessageHandler(
        Map&lt;String, dynamic&gt; message) async {
      print("onLaunch: $message");
      // Or do other work.
    }
  
    initializeFcmNotification() async {
      flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
  
      var initializationSettingsAndroid =
      new AndroidInitializationSettings('ic_launcher');
      var initializationSettingsIOS = new IOSInitializationSettings(
          onDidReceiveLocalNotification: onDidReceiveLocalNotification);
      var initializationSettings = new InitializationSettings(
          initializationSettingsAndroid, initializationSettingsIOS);
      flutterLocalNotificationsPlugin.initialize(initializationSettings,
          onSelectNotification: onSelectNotification);
  
      if (Platform.isIOS) {
        iosSubscription = _fcm.onIosSettingsRegistered.listen((data) {
          // save the token  OR subscribe to a topic here
        });
  
        _fcm.requestNotificationPermissions(IosNotificationSettings());
      } else {
        _saveDeviceToken();
      }
  
      _fcm.configure(
        onMessage: (Map&lt;String, dynamic&gt; message) async {
          print("onMessage: $message");
        },
        //onBackgroundMessage: myBackgroundMessageHandler,
        onLaunch: (Map&lt;String, dynamic&gt; message) async {
          print("onLaunch: $message");
        },
        onResume: (Map&lt;String, dynamic&gt; message) async {
          print("onResume: $message");
        },
      );
    }
  
  ...}
  </code></pre>
  
  <p>In my AndroidManifest.xml I have:</p>
  
  <pre><code>&lt;activity
              android:name=".MainActivity"
  ...
  &lt;intent-filter&gt;
                  &lt;action android:name="FLUTTER_NOTIFICATION_CLICK" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
  </code></pre>
  
  <p>and, finally, inside the app/src/main/java//Application.java I have:</p>
  
  <pre><code>package &lt;my ID app&gt;;  --&gt; the same ID in google-services.json
  
  import io.flutter.app.FlutterApplication;
  import io.flutter.plugin.common.PluginRegistry;
  import io.flutter.plugins.GeneratedPluginRegistrant;
  
  import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
  import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
  
  
  public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
      @Override
      public void onCreate() {
          super.onCreate();
          FlutterFirebaseMessagingService.setPluginRegistrant(this);
      }
  
      @Override
      public void registerWith(PluginRegistry registry) {
          GeneratedPluginRegistrant.registerWith(registry);
      }
  }
  </code></pre>
  
  <p>Well, the app start OK, and, in foreground, when I send a notification, the app stop and I can see this error message:</p>
  
  <pre><code>D/AndroidRuntime(26933): Shutting down VM
  E/AndroidRuntime(26933): FATAL EXCEPTION: main
  E/AndroidRuntime(26933): Process: br.com.htsnet.emergencia, PID: 26933
  E/AndroidRuntime(26933): java.lang.RuntimeException: Unable to create service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.RuntimeException: PluginRegistrantCallback is not set.
  E/AndroidRuntime(26933):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3167)
  E/AndroidRuntime(26933):    at android.app.ActivityThread.access$1900(ActivityThread.java:177)
  E/AndroidRuntime(26933):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
  E/AndroidRuntime(26933):    at android.os.Handler.dispatchMessage(Handler.java:102)
  E/AndroidRuntime(26933):    at android.os.Looper.loop(Looper.java:145)
  E/AndroidRuntime(26933):    at android.app.ActivityThread.main(ActivityThread.java:5951)
  E/AndroidRuntime(26933):    at java.lang.reflect.Method.invoke(Native Method)
  E/AndroidRuntime(26933):    at java.lang.reflect.Method.invoke(Method.java:372)
  E/AndroidRuntime(26933):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
  E/AndroidRuntime(26933):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
  E/AndroidRuntime(26933): Caused by: java.lang.RuntimeException: PluginRegistrantCallback is not set.
  E/AndroidRuntime(26933):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:157)
  E/AndroidRuntime(26933):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:77)
  E/AndroidRuntime(26933):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3157)
  E/AndroidRuntime(26933):    ... 9 more
  </code></pre>
  
  <p>I am using Android Studio 3.5, Firebase Functions to send notification whith data in paypload (click_action: 'FLUTTER_NOTIFICATION_CLICK').</p>