dart 扑动本地通知:尝试对空对象引用调用虚方法“int java.lang.Integer.intValue()”

bvjveswy  于 2023-01-06  发布在  Java
关注(0)|答案(1)|浏览(116)

我正在尝试为Flutter应用创建本地通知,但在编译时遇到问题。
我的代码:

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationService {
  static final notifications = FlutterLocalNotificationsPlugin();

  static Future detailsNotification() async {
    return const NotificationDetails(
        android: AndroidNotificationDetails('channel id', 'channel name',
            channelDescription: 'channel description',
            importance: Importance.max),
        iOS: IOSNotificationDetails());
  }

  static Future init({bool initScheduled = false}) async {
    final android = AndroidInitializationSettings("@mipmap/ic_launcher");
    final ios = IOSInitializationSettings();
    final settings = InitializationSettings(android: android, iOS: ios);
    await notifications.initialize(settings,
        onSelectNotification: (payload) async {});
  }

  static Future envoyerNotification(
          {int id = 0, String? title, String? body, String? payload}) async =>
      notifications.show(id, title, body, await detailsNotification(),
          payload: payload);
}

我得到的错误:

E/flutter (28521): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/flutter (28521):  at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:304)
E/flutter (28521):  at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:215)
E/flutter (28521):  at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1009)
E/flutter (28521):  at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1347)
E/flutter (28521):  at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1226)
E/flutter (28521):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)

我在StackOverflow上看到过类似的主题,但唯一的答案是使用Firebase,我不想使用它。谢谢你的帮助!

qgelzfjb

qgelzfjb1#

android:Android通知详细信息('通道ID','通道名称',通道描述:“渠道描述”,重要性:重要性。麦克斯,
图标:“@mipmap/ic_launcher”),

相关问题