根据Google的政策,我将targetSdkVersion和compileSdkVersion更新为31。但我注意到Flutter本地通知包现在对传入消息抛出错误,如下所示:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
我浏览了与此错误相关的所有堆栈溢出答案并进行了以下更改:
看起来
flutter_local_notifications
存储库中存在一个提供解决方案的问题。
在这里查看问题
如果您不想更新软件包的版本,您可以分叉,然后重置为包含当前版本代码的提交,并根据您正在使用的版本实施您自己的修复。
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationDetails.id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT)
固定为 PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationDetails.id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)