isValid method

  1. @override
Future<bool> isValid(
  1. bool fromAppStartup
)
override

If the trigger is valid or not. @param fromAppStartup If the check has been triggered at the app startup @returns If the trigger is valid or not.

Implementation

@override
Future<bool> isValid(bool fromAppStartup) async {
  if (!fromAppStartup) {
    return false;
  }
  int currentSession = await MBAudience.currentSession;
  DateTime? currentDate =
      await MBAudience.startSessionDateForSession(currentSession);
  if (currentDate == null) {
    return false;
  }
  DateTime? lastSessionDate =
      await MBAudience.startSessionDateForSession(currentSession - 1);
  if (lastSessionDate == null) {
    return false;
  }
  int days = currentDate.difference(lastSessionDate).inDays.abs();
  return days >= this.days;
}