首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数类型“未来函数(int,String,String)”不能分配给参数类型'void函数(int,String?,String?,String?,String?)?

参数类型“未来函数(int,String,String)”不能分配给参数类型'void函数(int,String?,String?,String?,String?)?
EN

Stack Overflow用户
提问于 2022-05-18 10:35:56
回答 1查看 85关注 0票数 0
代码语言:javascript
复制
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(

我在这个onDidReceiveLocalNotification上得到了一个错误,参数类型‘未来函数(int,String,String,String)’不能分配给参数类型'void函数(int,String?,String?,String?)?

代码语言:javascript
复制
  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);
 }
 }

我读过flutter_local_notifications自述,但我仍然不明白。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-18 10:39:15

onDidReceiveLocalNotification中的字符串应该是空的。试着改变:

代码语言:javascript
复制
Future onDidReceiveLocalNotification(
  int id, String title, String body, String payload) async {
  return Future.value(1);
}

至:

代码语言:javascript
复制
Future onDidReceiveLocalNotification(
      int id, String? title, String? body, String? payload) async {
      return Future.value(1);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72287573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档