save<T> method Null safety

Future<bool> save<T>(
  1. String key,
  2. T value
)

Implementation

Future<bool> save<T>(String key, T value) async {
  // Get SharedPreferences
  SharedPreferences refs = await SharedPreferences.getInstance();

  if (value == null) {
    refs.remove(key);
    return true;
  }
  if (value is String) {
    return refs.setString(key, value);
  } else if (value is bool) {
    return refs.setBool(key, value);
  } else if (value is int) {
    return refs.setInt(key, value);
  } else if (value is double) {
    return refs.setDouble(key, value);
  } else if (value is List<String>) {
    return refs.setStringList(key, value);
  }
  return false;
}