I am using Flutter flutter_local_notifications
package in an app targeting Android.
I’ve set up the example app and am running it in Android emulator (API33).
When I use Show plain notification with payload
it works, but when I click Schedule notification to appear in 5 seconds
, nothing! The notification does not appear. There is no error either.
I’ve changed the androidScheduleMode
to use “inexact” mode so I don’t need additional permissions:
Future<void> _zonedScheduleNotification() async {
final nowDttm =
tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5));
print('Scheduled: $nowDttm');
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'scheduled title',
'scheduled body',
nowDttm,
const NotificationDetails(
android: AndroidNotificationDetails(
'your channel id', 'your channel name',
channelDescription: 'your channel description')),
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle, //changed from exact
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
The notification that does work is using this method:
Future<void> _showNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('your channel id', 'your channel name',
channelDescription: 'your channel description',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.show(
id++, 'plain title', 'plain body', notificationDetails,
payload: 'item x');
}
App has notification permission as shown by the other type of notification working.
Other’s had problems with timezones but this is initialized correctly like so:
tz.initializeTimeZones();
final String timeZoneName = await FlutterTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(timeZoneName));
What am I missing here? How do I troubleshoot?