getBunchDataFromSp static method
Implementation
static Future<Map<String, dynamic>> getBunchDataFromSp(
{required Map<String, Type> data}) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
Map<String, dynamic> returnVal = {};
for (var entry in data.entries) {
var key = entry.key;
Type type = entry.value;
try {
if (type == String) {
returnVal[key] = prefs.getString(key) ?? '';
} else if (type == int) {
returnVal[key] = prefs.getInt(key) ?? 0;
} else if (type == double) {
returnVal[key] = prefs.getDouble(key) ?? 0.0;
} else if (type == bool) {
returnVal[key] = prefs.getBool(key) ?? false;
}
} catch (e) {
print(
'getBunchDataFromSp ==> Error retrieving $key from SharedPreferences: $e');
returnVal[key] = _getDefaultValue(type);
}
}
return returnVal;
}