Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

argument type 'Future Function(int, String, String, String)' can't be assigned to the parameter type 'void Function(int, String?, String?, String?)?

import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationManager {
// ignore: prefer_typing_uninitialized_variables
var flutterLocalNotificationsPlugin;

NotificationManager() {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
initNotifications();
 }

getNotificationInstance() {
return flutterLocalNotificationsPlugin;
}

void initNotifications() {
// initialise the plugin. app_icon needs to be a added as a drawable resource to the 
Android head project
const initializationSettingsAndroid =
    AndroidInitializationSettings('@mipmap/launcher_icon');
const initializationSettingsIOS = IOSInitializationSettings(

I AM GETTING AN ERROR ON THIS onDidReceiveLocalNotification
The argument type ‘Future Function(int, String, String, String)’ can’t be assigned to the parameter type ‘void Function(int, String?, String?, String?)?

  onDidReceiveLocalNotification: onDidReceiveLocalNotification);

const initializationSettings =  InitializationSettings(
    android: initializationSettingsAndroid, iOS: initializationSettingsIOS);

flutterLocalNotificationsPlugin.initialize(initializationSettings,
    onSelectNotification: onSelectNotification);
    }

void showNotificationDaily(
  int id, String title, String body, int hour, int minute) async {
var time = Time(hour, minute, 0);
await flutterLocalNotificationsPlugin.showDailyAtTime(
    id, title, body, time, getPlatformChannelSpecfics());
if (kDebugMode) {
  print('Notification Succesfully Scheduled at ${time.toString()}');
  }
 }

getPlatformChannelSpecfics() {
var androidPlatformChannelSpecifics = const AndroidNotificationDetails(
     'your channel name', 'your channel description',
    importance: Importance.max,
    priority: Priority.high,
    ticker: 'Sickle Cell');
var iOSPlatformChannelSpecifics = const IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
    android: androidPlatformChannelSpecifics, iOS: iOSPlatformChannelSpecifics);

 return platformChannelSpecifics;
 }

Future onSelectNotification(String payload) async {
if (kDebugMode) {
  print('Notification clicked');
  }
  return Future.value(0);
 }

 Future onDidReceiveLocalNotification(
  int id, String title, String body, String payload) async {
  return Future.value(1);
  }

 void removeReminder(int notificationId) {
 flutterLocalNotificationsPlugin.cancel(notificationId);
 }
 }

I have read the flutter_local_notifications readme but i am still not getting it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The strings in onDidReceiveLocalNotification should be nullable. Try changing:

Future onDidReceiveLocalNotification(
  int id, String title, String body, String payload) async {
  return Future.value(1);
}

To:

Future onDidReceiveLocalNotification(
      int id, String? title, String? body, String? payload) async {
      return Future.value(1);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading