Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase-messaging - Fatal: failed to find callback

I'm trying to use FCM messaging and keep getting this error.

E/FlutterFcmService( 3684): Fatal: failed to find callback

Below is the code I've used to setup.

  static Future<void> messagePiper(
      Map<String, dynamic> message,
      FilteredMap<String, ChatMessage> globalChatEntryMap,
      FilteredMap<String, ChatMessage> gameChatEntryMap,
      Subject<List<ChatMessage>> globalChatSubject,
      Subject<List<ChatMessage>> gameChatSubject,
      Map<String, Player> _playerMap) async {
    final Map<String, dynamic> data = message['data'];
    if (data.containsKey('name')) {
      final msg = ChatMessage.fromMap(data);
      globalChatEntryMap.putIfAbsent(msg.id, () => msg);
      globalChatSubject.add(globalChatEntryMap.values.toList());
    } else {
      final msg = GameChatMessage.fromMap(data);

      final chat = ChatMessage.fromGlobalChatMessage(
        msg,
        _playerMap[msg.pId].name,
        _playerMap[msg.pId].imageUrl,
      );

      print('chat: $chat');
      gameChatEntryMap.putIfAbsent(msg.id, () => chat);
      print('_gameChatEntryMap : $gameChatEntryMap');
      gameChatSubject.add(gameChatEntryMap.values.toList());
    }

    return Future<void>.value();
  }

is the callback passed in to FirebaseMessaging configuration.

  final FirebaseMessaging _fm = FirebaseMessaging();

  @override
  void initState() {

   _fm.configure(
        onMessage: (Map<String, dynamic> message) async {
          print('onMessagee : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
        },
        onLaunch: (Map<String, dynamic> message) async {
          print('onLaunch : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
          ;
        },
        onResume: (Map<String, dynamic> message) async {
          print('onResume : $message');
          return Utils.messagePiper(
              message,
              _globalChatEntryMap,
              _gameChatEntryMap,
              _globalChatSubject,
              _gameChatSubject,
              _playerMap);
          ;
        },
        onBackgroundMessage: null);
....

Java configuration file

package io.flutter.plugins;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
    @Override
    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        GeneratedPluginRegistrant.registerWith(registry);
    }
}

dependency versions

  random_string: 0.0.2
  firebase_auth: ^0.14.0+5
  firebase_database: ^3.0.7
  provider: 3.0.0
  rxdart: ^0.22.2
  collection: ^1.14.11
  audioplayers: ^0.13.2
  firebase_admob: ^0.5.5
  connectivity: ^0.4.4
  firebase_messaging: ^5.1.6 # tried with several different versions

I tried with several firebase_messaging versions but couldn't find a fix.

Appreciate any help to solve this issue.

like image 825
tharindu_DG Avatar asked Sep 29 '19 15:09

tharindu_DG


2 Answers

This error message is coming from startBackgroundIsolate which is used for allowing handling background messages. If you don't want to handle background messages then you can safely ignore this error message. Otherwise, you need to set up a callback for handling background messages as described here

If your callback is not executed when clicking on the notification then it's because you didn't set click_action property of the message to FLUTTER_NOTIFICATION_CLICK

like image 189
Morad Avatar answered Nov 13 '22 06:11

Morad


Are you sending FCM using the web, not FCM console? make sure the post request is correct on your backend. I'm using Laravel

$response = Http::withHeaders([
            'Content-Type' => 'application/json',
            'Authorization'=> 'key='. $token,
        ])->post($url, [
            'notification' => [
                'body' => $request->summary,
                'title' => $request->title,
                'image' => request()->getHttpHost().$path,
                
            ],
            'priority'=> 'high',
            'data' => [
                'click_action'=> 'FLUTTER_NOTIFICATION_CLICK',
                
                'status'=> 'done',
                
            ],
            'to' => '/topics/all'
        ]);
like image 4
James Christian Kaguo Avatar answered Nov 13 '22 05:11

James Christian Kaguo