Skip to content

Commit

Permalink
Type-related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
n-bernat committed Sep 7, 2024
1 parent 44d2cbc commit 1962cc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 0.3.0

- **BREAKING**: Fix type errors for a list of custom items.
- **BREAKING**: `fromJson` and `toJson` require `Object` instead of `Map<String, Object?>`.
- **BREAKING**: `fromJson` and `toJson` require `dynamic` instead of `Map<String, Object?>`.

## 0.2.0

Expand Down
10 changes: 5 additions & 5 deletions lib/flutter_app_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Preference<T extends Object> extends ValueNotifier<T> {
String key,
super.initialValue, {
List<T>? values,
T Function(Object json)? fromJson,
Object Function(T item)? toJson,
T Function(dynamic json)? fromJson,
dynamic Function(T item)? toJson,
}) : assert(
initialValue is! Enum || (values != null),
'You have to provide a list of possible `values` for an enum type.',
Expand All @@ -68,8 +68,8 @@ class Preference<T extends Object> extends ValueNotifier<T> {
final String _key;
final T _initialValue;
final List<T>? _values;
final Object Function(T)? _toJson;
final T Function(Object)? _fromJson;
final dynamic Function(T)? _toJson;
final T Function(dynamic)? _fromJson;

bool _initialized = false;
T? _value;
Expand Down Expand Up @@ -119,7 +119,7 @@ class Preference<T extends Object> extends ValueNotifier<T> {
_prefs?.getStringList(_key)?.map(double.parse).toList(),
// Custom objects
_ => (_prefs?.containsKey(_key) ?? false)
? _fromJson!(_prefs!.getString(_key)! as Map<String, dynamic>)
? _fromJson!(jsonDecode(_prefs!.getString(_key)!))
: null,
} as T?;

Expand Down

0 comments on commit 1962cc1

Please sign in to comment.