showPopup method

Future<bool> showPopup(
  1. int frequency,
  2. String action
)

Implementation

Future<bool> showPopup(int frequency, String action) async {
  final prefs = await SharedPreferences.getInstance();

  final DateTime now = DateTime.now();
  final String formattedDate = '${now.day}-${now.month}-${now.year}';

  final String savedDate = prefs.getString('CURRENT_DATE' + action) ?? '';

  if (savedDate != formattedDate) {
    await prefs.setString('CURRENT_DATE' + action, formattedDate);
    await prefs.setInt('COUNTER' + action, 0);
    return true;
  } else {
    int count = prefs.getInt('COUNTER' + action) ?? -1;
    count++;

    await prefs.setInt('COUNTER' + action, count);
    return count < frequency;
  }
}