Skip to content

Commit

Permalink
feat add setListOrNull setMapOrNull
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Oct 18, 2024
1 parent db0ca3f commit a02b9ff
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions prefs/lib/src/prefs_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,22 @@ extension PrefsAsyncExt on PrefsAsync {
Future<void> setBoolOrNull(String key, bool? value) =>
value == null ? remove(key) : setBool(key, value);

/// Set or remove an int value
/// Set or remove a string value
Future<void> setStringOrNull(String key, String? value) =>
value == null ? remove(key) : setString(key, value);

/// Set or remove an int value
/// Set or remove a double value
Future<void> setDoubleOrNull(String key, double? value) =>
value == null ? remove(key) : setDouble(key, value);

/// Set or remove a map value (json encodable)
/// Set a map value (json encodable)
Future<void> setMap(String key, Map value) =>
setString(key, jsonEncode(value));

/// Set or remove a map value (json encodable)
Future<void> setMapOrNull(String key, Map? value) =>
value == null ? remove(key) : setMap(key, value);

/// Set or remove a map value
Future<Model?> getMap(String key) async =>
cvAnyToJsonObjectOrNull(await getString(key));
Expand All @@ -101,6 +105,10 @@ extension PrefsAsyncExt on PrefsAsync {
Future<void> setList(String key, List value) =>
setString(key, jsonEncode(value));

/// Set or remove a list value (json encodable)
Future<void> setListOrNull(String key, List? value) =>
value == null ? remove(key) : setList(key, value);

/// Set or remove a list value
Future<List<Object?>?> getList(String key) async =>
cvAnyToJsonArrayOrNull(await getString(key));
Expand Down

0 comments on commit a02b9ff

Please sign in to comment.