Home > Net >  The argument type 'Future<Null> Function(String)' can't be assigned to the para
The argument type 'Future<Null> Function(String)' can't be assigned to the para

Time:11-20

Didn't think that I'll be asking for help on stackoverflow but yeah, I'm stuck... So after the updating of flutter_local_notifications , I've change the method to Darwin and after that I can't build the app because of an error 'The argument type 'Future Function(String)' can't be assigned to the parameter type '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;
  });

What I've do wrong? And what should I do to fix that error. Thanks a lot

Upgraded the flutter_local_notifications, changed the method to Darwin. Some errors was fixed.

CodePudding user response:

i think you should add await here:

await flutterLocalNotificationsPlugin.initialize

and remove all new, you dont need it anymore

CodePudding user response:

Thanks a lot for the help. Sadly, I can't to rate up Stellar Creed. So I fix that error for a time at least. Just downgraded the flutter_local_notifications to v.9 but you can downgrade to another one below the v.11.

Also I returned the methods from Darwin to the previous one. If I'll get some time, I will try to fix that code. Bot for now only downgrade helps.

  • Related