簡體   English   中英

參數類型 'Future<null> Function(String)' 不能分配給參數類型 'void Function(NotificationResponse)'</null>

[英]The argument type 'Future<Null> Function(String)' can't be assigned to the parameter type 'void Function(NotificationResponse)'

沒想到我會在 stackoverflow 上尋求幫助,但是,是的,我被困住了……所以在更新 flutter_local_notifications 之后,我將方法更改為 Darwin,之后我無法構建應用程序,因為錯誤“參數類型‘Future Function(String)’無法分配給參數類型‘void Function(NotificationResponse)’”

static Future<void> initialize(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
  var androidInitialize = new AndroidInitializationSettings('notification_icon');
  var iOSInitialize = new  DarwinInitializationSettings();
  var initializationsSettings = new InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
  flutterLocalNotificationsPlugin.initialize (initializationsSettings, onDidReceiveNotificationResponse: (String payload) async {
    try{
      NotificationBody _payload;
      if(payload != null && payload.isNotEmpty) {
        _payload = NotificationBody.fromJson(jsonDecode(payload));
        if(_payload.notificationType == NotificationType.order) {
          Get.toNamed(RouteHelper.getOrderDetailsRoute(int.parse(_payload.orderId.toString())));
        } else if(_payload.notificationType == NotificationType.general) {
          Get.toNamed(RouteHelper.getNotificationRoute());
        } else{
          Get.toNamed(RouteHelper.getChatRoute(notificationBody: _payload, conversationID: _payload.conversationId));
        }
      }
    }catch (e) {}
    return;
  });

我做錯了什么? 我應該怎么做才能修復該錯誤。 非常感謝

升級了 flutter_local_notifications,將方法更改為 Darwin。 一些錯誤是固定的。

我認為你應該在這里添加 await :

await flutterLocalNotificationsPlugin.initialize

並刪除所有new的,你不再需要它了

非常感謝您的幫助。 可悲的是,我無法評價 Stellar Creed。 所以我至少修復了一段時間的錯誤。 剛剛將 flutter_local_notifications 降級到 v.9,但你可以降級到 v.11 以下的另一個。

我還把 Darwin 的方法返回到以前的方法。 如果我有時間,我會嘗試修復該代碼。 Bot 目前只有降級幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM