'Even after Applying right logic still not to show local notification in flutter?

I have applied this below logic in my app to show notifications on the timing user has provided from cloud firestore.

void shownotifications() {
  for (int i = 0; i < snapshot.data!.size; i++) {
    for (int z = 0;
        z < snapshot.data!.docs[i]['date'].length;
        z++) {
      print('notified');
      final _notifications =
          FlutterLocalNotificationsPlugin();
      _notifications.zonedSchedule(
        0,
        '${snapshot.data!.docs[i]['title']}',
        '${snapshot.data!.docs[i]['description']}',
        tz.TZDateTime.from(
            snapshot.data!.docs[i]['date'][z].toDate().add(Duration(
                hours: int.parse(
                    '${snapshot.data!.docs[i]['time_hour']}'),
                minutes: int.parse(
                    '${snapshot.data!.docs[i]['time_minute']}'))),
            tz.local),
        const NotificationDetails(
            android: AndroidNotificationDetails(
          'channel id',
          'channel name'
              'channel description',
          importance: Importance.defaultImportance,
          icon: '@mipmap/ic_launcher',
          autoCancel: false,

          // showProgress: false,
        )),
        payload: 'Hello World',
        androidAllowWhileIdle: true,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation
                .absoluteTime,
        matchDateTimeComponents:
            DateTimeComponents.dateAndTime,
      );
    }
  }
}

Everything thing is correct but still I am not able to display notifications only sometimes it display and sometimes not . Is there any problem with logic of this code or what ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source