shouldShow method
- String? appVersion,
Returns true when all conditions are met and the prompt should appear.
Implementation
Future<bool> shouldShow({String? appVersion}) async {
final prefs = SharedPreferencesAsync();
if ((await prefs.getBool(_kNeverShowKey)) == true) return false;
final launches = (await prefs.getInt(_kLaunchCountKey)) ?? 0;
if (launches < minAppLaunches) return false;
final firstLaunch = await prefs.getInt(_kFirstLaunchKey);
if (firstLaunch != null) {
final daysSinceInstall = DateTime.now()
.difference(DateTime.fromMillisecondsSinceEpoch(firstLaunch))
.inDays;
if (daysSinceInstall < minDaysInstalled) return false;
}
final lastShown = await prefs.getInt(_kLastShownKey);
if (lastShown != null) {
final daysSinceShown = DateTime.now()
.difference(DateTime.fromMillisecondsSinceEpoch(lastShown))
.inDays;
if (daysSinceShown < repeatAfterDays) return false;
}
if (oncePerVersion && appVersion != null) {
final lastVersion = await prefs.getString(_kLastVersionKey);
if (lastVersion == appVersion) return false;
}
return true;
}