shouldShowPeriodicReminder method

Future<bool> shouldShowPeriodicReminder({
  1. int? intervalDays,
})

Returns true if enough time has passed to show a periodic reminder.

Uses the interval configured in NotificationService (default 30 days).

Implementation

Future<bool> shouldShowPeriodicReminder({int? intervalDays}) async {
  try {
    await ensureMigrated();
    final prefs = await SharedPreferences.getInstance();
    final lastReminder = prefs.getInt(_keyLastReminderDate);

    if (lastReminder == null) {
      return true; // Never shown before
    }

    final daysSinceLastReminder = DateTime.now()
        .difference(DateTime.fromMillisecondsSinceEpoch(lastReminder))
        .inDays;

    final interval = intervalDays ?? 30;
    return daysSinceLastReminder >= interval;
  } catch (e) {
    loge(e, 'Error checking should show periodic reminder');
    return false;
  }
}