'flutter local notification schedule notification causing app crash
I have set up flutter_local_notifications for schedule notification but it is causing a crash in my android 11 device on release mode whenever the schedule notification is called.
schedule.dart
@override
void initState() {
super.initState();
NotificationApi.init(initScheduled: true);
}
notification.dart
static final _notifications = FlutterLocalNotificationsPlugin();
static Future _notificationDetails() async {
return const NotificationDetails(
android: AndroidNotificationDetails(
"channelId 4",
"channelName",
importance: Importance.max,
),
);
}
static Future init({bool initScheduled = false}) async {
const android = AndroidInitializationSettings("@mipmap/ic_launcher");
const setting = InitializationSettings(android: android);
await _notifications.initialize(setting, onSelectNotification: null);
if (initScheduled) {
tz.initializeTimeZones();
final locationName = await FlutterNativeTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(locationName));
}
}
static Future showNotification({
required int id,
required String title,
required String body,
required DateTime scheduledDate,
}) async =>
_notifications.zonedSchedule(
id,
title,
body,
tz.TZDateTime.from(scheduledDate, tz.local),
await _notificationDetails(),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);
AndroidManifest.xml
....
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET"/>
....
....
<service
android:name="com.dexterous.flutterlocalnotifications.ForegroundService"
android:exported="false"
android:stopWithTask="false"/>
....
I am getting an error after the crash: E/AndroidRuntime(17107): java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.RuntimeException: Missing type parameter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
