compareValuesInSharedPreference function

Future<bool> compareValuesInSharedPreference(
  1. String key,
  2. dynamic value
)

Implementation

Future<bool> compareValuesInSharedPreference(String key, dynamic value) async {
  bool status = false;
  try {
    if (value is String) {
      status = getStringAsync(key) == value;
    } else if (value is bool) {
      status = getBoolAsync(key) == value;
    } else if (value is int) {
      status = getIntAsync(key) == value;
    } else if (value is double) {
      status = getDoubleAsync(key) == value;
    }

    if (!status) {
      await setValue(key, value);
    }
  } catch (e) {
    log('compareValuesInSharedPreference Error: $e');
  }

  return status;
}