Local scheduled notifications not working

I have been trying to allow for local notifications. I have a simple static notification working fine:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Future<void> showNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('your channel id', 'your channel name',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker');
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.show(0, 'Working Notifications',
'Flutter Notifications', notificationDetails,
payload: 'item x');
}
</code>
<code>Future<void> showNotification() async { const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails('your channel id', 'your channel name', importance: Importance.max, priority: Priority.high, ticker: 'ticker'); const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show(0, 'Working Notifications', 'Flutter Notifications', notificationDetails, payload: 'item x'); } </code>
Future<void> showNotification() async {
const AndroidNotificationDetails androidNotificationDetails =
    AndroidNotificationDetails('your channel id', 'your channel name',
        importance: Importance.max,
        priority: Priority.high,
        ticker: 'ticker');

const NotificationDetails notificationDetails =
    NotificationDetails(android: androidNotificationDetails);

await flutterLocalNotificationsPlugin.show(0, 'Working Notifications',
    'Flutter Notifications', notificationDetails,
    payload: 'item x');
}

However, as I try to get scheduled notifications working I run into many issues. Permissions for exact alarms, I’ve come up with a workaround by using_ALARMS permission but may end up using inexact depending on the inaccuracy.
TZ was throwing up errors but I made sure the correct timezone was set and initialised within main.dart before initialising the notification service:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Future<void> initNotification() async {
AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('test_noti');
var initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse: selectNotification);
var details =
await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
if (details?.didNotificationLaunchApp ?? false) {
var activeNotifications =
await flutterLocalNotificationsPlugin.getActiveNotifications();
if (activeNotifications.isNotEmpty) {
debugPrint(
'Notification launched app: ${activeNotifications.first.payload}');
}
}
}
</code>
<code>Future<void> initNotification() async { AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('test_noti'); var initializationSettings = InitializationSettings(android: initializationSettingsAndroid); await flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: selectNotification); var details = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); if (details?.didNotificationLaunchApp ?? false) { var activeNotifications = await flutterLocalNotificationsPlugin.getActiveNotifications(); if (activeNotifications.isNotEmpty) { debugPrint( 'Notification launched app: ${activeNotifications.first.payload}'); } } } </code>
Future<void> initNotification() async {
    AndroidInitializationSettings initializationSettingsAndroid =
        AndroidInitializationSettings('test_noti');

    var initializationSettings =
        InitializationSettings(android: initializationSettingsAndroid);

    await flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onDidReceiveNotificationResponse: selectNotification);

    var details =
        await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();

    if (details?.didNotificationLaunchApp ?? false) {
      var activeNotifications =
          await flutterLocalNotificationsPlugin.getActiveNotifications();

      if (activeNotifications.isNotEmpty) {
        debugPrint(
            'Notification launched app: ${activeNotifications.first.payload}');
      }
    }
  }

Scheduled notification function:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Future<void> testSchedule() async {
var permissionStatus = await Permission.scheduleExactAlarm.request();
if (permissionStatus.isGranted) {
debugPrint('USE_EXACT_ALARM permission granted');
} else {
debugPrint('USE_EXACT_ALARM permission denied');
}
tz.TZDateTime scheduledDate =
tz.TZDateTime.now(tz.local).add(Duration(seconds: 5));
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'scheduled title',
'scheduled body',
scheduledDate,
NotificationDetails(
android: AndroidNotificationDetails('0', 'your channel name',
channelDescription: 'your channel description')),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
matchDateTimeComponents: DateTimeComponents.time,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
debugPrint('Scheduled for $scheduledDate');
debugPrint('Current date ${tz.TZDateTime.now(tz.local)}');
}
</code>
<code>Future<void> testSchedule() async { var permissionStatus = await Permission.scheduleExactAlarm.request(); if (permissionStatus.isGranted) { debugPrint('USE_EXACT_ALARM permission granted'); } else { debugPrint('USE_EXACT_ALARM permission denied'); } tz.TZDateTime scheduledDate = tz.TZDateTime.now(tz.local).add(Duration(seconds: 5)); await flutterLocalNotificationsPlugin.zonedSchedule( 0, 'scheduled title', 'scheduled body', scheduledDate, NotificationDetails( android: AndroidNotificationDetails('0', 'your channel name', channelDescription: 'your channel description')), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, matchDateTimeComponents: DateTimeComponents.time, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime); debugPrint('Scheduled for $scheduledDate'); debugPrint('Current date ${tz.TZDateTime.now(tz.local)}'); } </code>
Future<void> testSchedule() async {
    var permissionStatus = await Permission.scheduleExactAlarm.request();
    if (permissionStatus.isGranted) {
      debugPrint('USE_EXACT_ALARM permission granted');
    } else {
      debugPrint('USE_EXACT_ALARM permission denied');
    }

    tz.TZDateTime scheduledDate =
        tz.TZDateTime.now(tz.local).add(Duration(seconds: 5));

    await flutterLocalNotificationsPlugin.zonedSchedule(
        0,
        'scheduled title',
        'scheduled body',
        scheduledDate,
        NotificationDetails(
            android: AndroidNotificationDetails('0', 'your channel name',
                channelDescription: 'your channel description')),
        androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
        matchDateTimeComponents: DateTimeComponents.time,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation.absoluteTime);

    debugPrint('Scheduled for $scheduledDate');
    debugPrint('Current date ${tz.TZDateTime.now(tz.local)}');
  }

Function output:
Output of flutter app

There are 0 other errors or crashes that happen and that’s all the information I get from running the function, the date and time seem to line up fine, the notifications are allowed on my device, dnd silent powersaving are all turned off meaning the fix must be in the code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật