本地通知抖动导致崩溃 -> message_codecs.dart StandardMethodCodec.decodeEnvelope

问题描述 投票:0回答:1

您好,我在我的应用程序上添加了本地通知,但我在 firebase crashlytics 上遇到了一些崩溃。

这是我的代码和错误

 @override
  void initState() {
  // TODO: implement initState
  super.initState();
   check_notification();
 }

check_notification()async{

FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

if(toggle_notification==false){

  _flutterLocalNotificationsPlugin.cancelAll;
}
 else{
  intialize();
  ScheduledNotification_remove();
 }
}



final _localNotificationService = FlutterLocalNotificationsPlugin();


Future<void> intialize() async {
tz.initializeTimeZones();
const AndroidInitializationSettings androidInitializationSettings =
AndroidInitializationSettings('@drawable/ic_launcher');


final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
  onDidReceiveLocalNotification: onDidReceiveLocalNotification,

  requestSoundPermission: true,
  requestBadgePermission: true,
  requestAlertPermission: true,

);

final InitializationSettings settings = InitializationSettings(
  android: androidInitializationSettings,
  iOS: initializationSettingsDarwin,

);

await _localNotificationService.initialize(
  settings,
  // onSelectNotification: onSelectNotification,
    );
           }


       

  Future<NotificationDetails> _notificationDetails() async {
  const AndroidNotificationDetails androidNotificationDetails =
   AndroidNotificationDetails('channel_id', 'channel_name',
    channelDescription: 'description',
    importance: Importance.max,
    priority: Priority.high,
    enableVibration: true,
    playSound: true

);

const DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(
    presentSound: true,
    presentAlert: true,
    presentBadge: true);


return  NotificationDetails(
  android: androidNotificationDetails,
  iOS: darwinNotificationDetails,
  );
 }


 Future<void> showScheduledNotification(
  {required int id,
    required String title,
    required String body,
    required int seconds}) async {
final details = await _notificationDetails();

await _localNotificationService.zonedSchedule(
  id,
  title,
  body,
  tz.TZDateTime.from(
    DateTime.now().add(Duration(seconds: seconds)),
    tz.local,
  ),


  details,
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation:
  UILocalNotificationDateInterpretation.absoluteTime,

);
}


ScheduledNotification_remove()async{



final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

_flutterLocalNotificationsPlugin.cancel(1);
_flutterLocalNotificationsPlugin.cancel(2);
_flutterLocalNotificationsPlugin.cancel(3);
_flutterLocalNotificationsPlugin.cancel(4);
_flutterLocalNotificationsPlugin.cancel(5);


 showScheduledNotification(
      id: 1,
      title: 'title1',
      body: "body1",
      seconds: 1,
 }


showScheduledNotification(
      id: 2,
      title: 'title2',
      body: "body2",
      seconds: 2,
 }


 showScheduledNotification(
      id: 3,
      title: 'title3',
      body: "body3",
      seconds: 3,
 }

 showScheduledNotification(
      id: 4,
      title: 'title4',
      body: "body4",
      seconds: 4,
 }

 showScheduledNotification(
      id: 5,
      title: 'title5',
      body: "body5",
      seconds: 5,
  }
 }

 Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Missing type parameter., null, java.lang.RuntimeException: Missing type parameter.
    at g.c.d.T.a.<init>(:3)
    at com.dexterous.flutterlocalnotifications.c.<init>(Unknown Source:0)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.loadScheduledNotifications(Unknown Source:25)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.removeNotificationFromCache(Unknown Source:0)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.cancelNotification(Unknown Source:53)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.cancel(:2)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(Unknown Source:389)
    at j.a.e.a.y.a(Unknown Source:17)
    at io.flutter.embedding.engine.n.q.i(Unknown Source:11)
    at io.flutter.embedding.engine.n.q.j(:3)
    at io.flutter.embedding.engine.n.c.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:233)
    at android.os.Looper.loop(Looper.java:344)
    at android.app.ActivityThread.main(ActivityThread.java:8205)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)
). Error thrown null.
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:607)
       at MethodChannel._invokeMethod(platform_channel.dart:177)
       at FlutterLocalNotificationsPlugin.cancel(flutter_local_notifications_plugin.dart:274)

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.RuntimeException: Missing type parameter.
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:4890)
       at android.app.ActivityThread.-$$Nest$mhandleReceiver(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2417)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8741)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
flutter flutter-local-notification
1个回答
0
投票

导致我来到这里的错误与“颤动本地通知”[FLN](我使用过的一个包)相关的“无效信封”错误有关。

就我而言,这是一个全新的错误 - 之前一切都很好,但是,我刚刚完成了 Android 图标的更改,在此期间我删除了默认的 Android 图标并更改了文件名的默认名称。

偶然,我查看了 FLN 代码,发现其中引用了 Android 通知图标的默认名称,因此我将其更改为反映新名称和图标,然后再次运行我的代码,然后一切都和以前一样好。

在你的情况下,如果你的错误原因与我的相同,那么我注意到你的代码引用了默认的Android图标名称“@drawable/ic_launcher”。一方面这可能是问题,但另一方面,默认情况下我的代码引用 mipmap 目录(适用于应用程序图标,但不适用于通知图标)。

所以请检查一下,您指的是已更改的图标名称(就像我一样)吗?或者,是因为您引用的是drawable而不是mipmap,所以出现了错误?

© www.soinside.com 2019 - 2024. All rights reserved.