<tfoot id='yxipS'></tfoot>

      <small id='yxipS'></small><noframes id='yxipS'>

      • <bdo id='yxipS'></bdo><ul id='yxipS'></ul>
      <i id='yxipS'><tr id='yxipS'><dt id='yxipS'><q id='yxipS'><span id='yxipS'><b id='yxipS'><form id='yxipS'><ins id='yxipS'></ins><ul id='yxipS'></ul><sub id='yxipS'></sub></form><legend id='yxipS'></legend><bdo id='yxipS'><pre id='yxipS'><center id='yxipS'></center></pre></bdo></b><th id='yxipS'></th></span></q></dt></tr></i><div id='yxipS'><tfoot id='yxipS'></tfoot><dl id='yxipS'><fieldset id='yxipS'></fieldset></dl></div>
      <legend id='yxipS'><style id='yxipS'><dir id='yxipS'><q id='yxipS'></q></dir></style></legend>
      1. 未处理的异常:NoSuchMethodError:方法 'toRawHandle' 在 null 上被调

        Unhandled Exception: NoSuchMethodError: The method #39;toRawHandle#39; was called on null(未处理的异常:NoSuchMethodError:方法 toRawHandle 在 null 上被调用)
          <i id='7IkTw'><tr id='7IkTw'><dt id='7IkTw'><q id='7IkTw'><span id='7IkTw'><b id='7IkTw'><form id='7IkTw'><ins id='7IkTw'></ins><ul id='7IkTw'></ul><sub id='7IkTw'></sub></form><legend id='7IkTw'></legend><bdo id='7IkTw'><pre id='7IkTw'><center id='7IkTw'></center></pre></bdo></b><th id='7IkTw'></th></span></q></dt></tr></i><div id='7IkTw'><tfoot id='7IkTw'></tfoot><dl id='7IkTw'><fieldset id='7IkTw'></fieldset></dl></div>
            <bdo id='7IkTw'></bdo><ul id='7IkTw'></ul>

              <tbody id='7IkTw'></tbody>
          • <small id='7IkTw'></small><noframes id='7IkTw'>

            1. <legend id='7IkTw'><style id='7IkTw'><dir id='7IkTw'><q id='7IkTw'></q></dir></style></legend>

                <tfoot id='7IkTw'></tfoot>
                • 本文介绍了未处理的异常:NoSuchMethodError:方法 'toRawHandle' 在 null 上被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的 Flutter 应用程序中使用 firebase_messaging 库进行 Firebase 推送通知.

                  i am using firebase_messaging library in My Flutter Application for Firebase Push Notifications.

                  目前我的 firebase_messaging 版本是 firebase_messaging: ^5.1.5,最近更新为最新版本.

                  Currently my firebase_messaging version is firebase_messaging: ^5.1.5 which was recently updated an the latest one.

                  我正在尝试在后台以及应用程序终止时接收通知.

                  i am trying to receive notification in background as well as when application is terminated.

                  我已按照 firebase_messaging 文档中提到的所有步骤进行操作,但不幸的是,我在 Flutter 中遇到了上述错误.

                  i have followed all the steps as mentioned in the documentation of firebase_messaging but unfortunately i am getting the above error in flutter.

                  这是我在 dart 中的通知处理程序类

                  this is my notification handler class in dart

                  notification_handler.dart

                  import 'dart:async';
                  import 'dart:io';
                  import 'dart:math';
                  
                  import 'package:firebase_messaging/firebase_messaging.dart';
                  import 'package:flutter/cupertino.dart';
                  import 'package:flutter_local_notifications/flutter_local_notifications.dart';
                  import 'package:path_provider/path_provider.dart';
                  import 'package:http/http.dart' as http;
                  
                  class NotificationHandler {
                    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
                    FirebaseMessaging _fcm = FirebaseMessaging();
                    StreamSubscription iosSubscription;
                    static final NotificationHandler _singleton =
                        new NotificationHandler._internal();
                  
                    factory NotificationHandler() {
                      return _singleton;
                    }
                    NotificationHandler._internal();
                  
                    Future<dynamic> myBackgroundMessageHandler(
                        Map<String, dynamic> message) async {
                      print("onLaunch: $message");
                      _showBigPictureNotification(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<String, dynamic> message) async {
                          print("onMessage: $message");
                          _showBigPictureNotification(message);
                        },
                        onBackgroundMessage: myBackgroundMessageHandler,
                        onLaunch: (Map<String, dynamic> message) async {
                          print("onLaunch: $message");
                        },
                        onResume: (Map<String, dynamic> message) async {
                          print("onResume: $message");
                        },
                      );
                    }
                  
                    /// Get the token, save it to the database for current user
                    _saveDeviceToken() async {
                      String fcmToken = await _fcm.getToken();
                      print("FCM_TOKEN: $fcmToken");
                    }
                  
                    Future<void> _showBigPictureNotification(message) async {
                      var rng = new Random();
                      var notifId = rng.nextInt(100);
                  
                      var largeIconPath = await _downloadAndSaveImage(
                          'https://cdn.pixabay.com/photo/2019/04/21/21/29/pattern-4145023_960_720.jpg',
                          'largeIcon');
                      var bigPicturePath = await _downloadAndSaveImage(
                          'https://cdn.pixabay.com/photo/2019/04/21/21/29/pattern-4145023_960_720.jpg',
                          'bigPicture');
                      var bigPictureStyleInformation = BigPictureStyleInformation(
                          bigPicturePath, BitmapSource.FilePath,
                          largeIcon: largeIconPath,
                          largeIconBitmapSource: BitmapSource.FilePath,
                          contentTitle: message['data']['title'],
                          htmlFormatContentTitle: true,
                          summaryText: message['data']['body'],
                          htmlFormatSummaryText: true);
                      var androidPlatformChannelSpecifics = AndroidNotificationDetails(
                          '12', 'trading_id', message['data']['body'],
                          importance: Importance.High,
                          priority: Priority.High,
                          style: AndroidNotificationStyle.BigPicture,
                          styleInformation: bigPictureStyleInformation);
                      var platformChannelSpecifics =
                          NotificationDetails(androidPlatformChannelSpecifics, null);
                      await flutterLocalNotificationsPlugin.show(
                          notifId,
                          message['data']['title'],
                          message['data']['body'],
                          platformChannelSpecifics,
                          payload: message['data']['body']);
                    }
                  
                    Future<void> _showBigTextNotification(message) async {
                      var rng = new Random();
                      var notifId = rng.nextInt(100);
                      var bigTextStyleInformation = BigTextStyleInformation(
                          message['data']['body'],
                          htmlFormatBigText: true,
                          contentTitle: message['data']['title'],
                          htmlFormatContentTitle: true,
                          summaryText: message['data']['body'],
                          htmlFormatSummaryText: true);
                      var androidPlatformChannelSpecifics = AndroidNotificationDetails(
                          '12', 'trading_id', '',
                          importance: Importance.High,
                          priority: Priority.High,
                          style: AndroidNotificationStyle.BigText,
                          styleInformation: bigTextStyleInformation);
                      var platformChannelSpecifics =
                          NotificationDetails(androidPlatformChannelSpecifics, null);
                      await flutterLocalNotificationsPlugin.show(
                          notifId,
                          message['data']['title'],
                          message['data']['body'],
                          platformChannelSpecifics,
                          payload: message['data']['body']);
                    }
                  
                    Future onSelectNotification(String payload) async {
                      if (payload != null) {
                        debugPrint('notification payload: ' + payload);
                      }
                      // await Navigator.push(
                      //   context,
                      //   new MaterialPageRoute(builder: (context) => new SecondScreen(payload)),
                      // );
                    }
                  
                    Future<void> onDidReceiveLocalNotification(
                        int id, String title, String body, String payload) async {
                      // display a dialog with the notification details, tap ok to go to another page
                    }
                  
                    Future<String> _downloadAndSaveImage(String url, String fileName) async {
                      var directory = await getApplicationDocumentsDirectory();
                      var filePath = '${directory.path}/$fileName';
                      var response = await http.get(url);
                      var file = File(filePath);
                      await file.writeAsBytes(response.bodyBytes);
                      return filePath;
                    }
                  }
                  

                  我在主屏幕上这样称呼它

                  and i have called it like this in my home screen

                     @override
                    void initState() {
                      // TODO: implement initState
                      super.initState();
                      new NotificationHandler().initializeFcmNotification();
                    }
                  

                  推荐答案

                  浏览了几个git线程和stackoverflow线程,终于找到了一个无人能说的最短答案:

                  After surfing for several git threads and stackoverflow threads, I finally found the shortest answer that no one could tell:

                  只需将处理程序放在全球范围内"

                  "JUST PUT THE HANDLERS IN GLOBAL SCOPE"

                  在您的whatever.dart 文件中,只需将_firebaseMessaging 和4 个处理程序、onMessage、onLaunch 等...放在本地类之外,瞧!没有崩溃!

                  in your whatever.dart file, just put the _firebaseMessaging and the 4 handlers, onMessage, onLaunch, etc... outside local class, and VOILA!! NO CRASH!

                  原文:

                  我使用 bkmza 回答,但不是跨平台的OP修复

                  I used bkmza answer , but was not OP fix for crossplatform

                  由于某种原因,设置

                  void initState() {
                  super.initState();
                      _firebaseMessaging.configure
                  }
                  

                  不工作,然后我尝试了

                  Future.delayed(Duration(seconds: 1), () {
                       _firebaseMessaging.configure
                      }
                  );
                  

                  我让它完美地工作:)

                  也许 FCM 初始化尚未准备好配置处理程序,在 Firebase Core 完全加载后设置延迟使其正常工作

                  Maybe FCM initialisations was not ready to configure handlers, setting a delay after Firebase Core fully load made it work properly

                  这篇关于未处理的异常:NoSuchMethodError:方法 'toRawHandle' 在 null 上被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                    <i id='G8Jbr'><tr id='G8Jbr'><dt id='G8Jbr'><q id='G8Jbr'><span id='G8Jbr'><b id='G8Jbr'><form id='G8Jbr'><ins id='G8Jbr'></ins><ul id='G8Jbr'></ul><sub id='G8Jbr'></sub></form><legend id='G8Jbr'></legend><bdo id='G8Jbr'><pre id='G8Jbr'><center id='G8Jbr'></center></pre></bdo></b><th id='G8Jbr'></th></span></q></dt></tr></i><div id='G8Jbr'><tfoot id='G8Jbr'></tfoot><dl id='G8Jbr'><fieldset id='G8Jbr'></fieldset></dl></div>

                  1. <legend id='G8Jbr'><style id='G8Jbr'><dir id='G8Jbr'><q id='G8Jbr'></q></dir></style></legend>
                    • <small id='G8Jbr'></small><noframes id='G8Jbr'>

                        <bdo id='G8Jbr'></bdo><ul id='G8Jbr'></ul>

                          <tbody id='G8Jbr'></tbody>

                            <tfoot id='G8Jbr'></tfoot>