Flutter:FCM 未处理异常:对空值使用空检查运算符 [英] Flutter: FCM Unhandled Exception: Null check operator used on a null value

查看:55
本文介绍了Flutter:FCM 未处理异常:对空值使用空检查运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

E/flutter (26872): [错误:flutter/lib/ui/ui_dart_state.cc(199)]未处理的异常:对空值使用空检查运算符E/颤振(26872):#0
MethodChannelFirebaseMessaging.registerBackgroundMessageHandler(包:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:173:53)E/颤振(26872):#1
FirebaseMessagingPlatform.onBackgroundMessage=(包:firebase_messaging_platform_interface/src/platform_interface/platform_interface_messaging.dart:108:16)

E/flutter (26872): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter (26872): #0
MethodChannelFirebaseMessaging.registerBackgroundMessageHandler (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:173:53) E/flutter (26872): #1
FirebaseMessagingPlatform.onBackgroundMessage= (package:firebase_messaging_platform_interface/src/platform_interface/platform_interface_messaging.dart:108:16)

// Background Messaging Set Up
    Future<void> _firebaseMessagingBackgroundHandler(
        RemoteMessage message) async {
      print('background message');
    }

    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
    runApp(....)

我在 Android 系统上收到此代码的错误.一切正常,除非应用程序终止.

I am getting an error for this code on Android system. Everything works except when the app is terminated.

什么适用于 Android:

  • 终止时的通知,onBackground 和 onForeground
  • 仅在前台显示日期

什么在 Android 上不起作用:

  • 仅在 Terminated 和 onBackground 时数据

适用于 iOS 的内容:

  • 终止时的通知,onBackground 和 onForeground
  • 仅在前台显示日期

什么在 iOS 上不起作用:

  • 仅在终止时提供数据,

我不知道为什么在 Android 系统上出现空值错误,我该如何解决这个问题?另外,当应用程序终止时,我无法在 iOS 上收到 Data only 推送通知是真的吗?

I have no clue why I am getting that null value error on Android system and how can I fix this issue? Also, is it true that I can not receive the Data only push notification on iOS when the app is terminated?

推荐答案

我和你一样有同样的错误,在同一行.我查看了 docs,它说明了关于后台消息处理程序的两件事.

I had the same error as like you, on the same line. I checked out docs and it says 2 things about background message handler.

  1. 它不能是匿名函数.
  2. 它必须是顶级函数(例如,不是需要初始化的类方法).

就我而言,它不是顶级函数,它是在类中声明的.当您将处理程序移出任何类或函数时,使其成为顶级函数并且不需要任何类或方法初始化,那么错误就会消失.

In my case it was not a top-level function, it was declared inside a class. When you move your handler out of any class or function, so that it is a top-level function and doesn't require any class or method initialisation then the error will be gone.

这篇关于Flutter:FCM 未处理异常:对空值使用空检查运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆