getJSONAsync function

Map<String, dynamic> getJSONAsync(
  1. String key, {
  2. Map<String, dynamic>? defaultValue,
})

Returns a JSON if exists in SharedPref

Implementation

Map<String, dynamic> getJSONAsync(String key,
    {Map<String, dynamic>? defaultValue}) {
  if (sharedPreferences.containsKey(key) &&
      sharedPreferences.getString(key).validate().isNotEmpty) {
    return jsonDecode(sharedPreferences.getString(key)!);
  } else {
    return defaultValue ?? {};
  }
}