diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f3e173..d376a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. +- **BREAKING**: `fromJson` and `toJson` require `dynamic` instead of `Map`. ## 0.2.0 diff --git a/lib/flutter_app_preferences.dart b/lib/flutter_app_preferences.dart index 5227691..cefb1b4 100644 --- a/lib/flutter_app_preferences.dart +++ b/lib/flutter_app_preferences.dart @@ -40,8 +40,8 @@ class Preference extends ValueNotifier { String key, super.initialValue, { List? 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.', @@ -68,8 +68,8 @@ class Preference extends ValueNotifier { final String _key; final T _initialValue; final List? _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; @@ -119,7 +119,7 @@ class Preference extends ValueNotifier { _prefs?.getStringList(_key)?.map(double.parse).toList(), // Custom objects _ => (_prefs?.containsKey(_key) ?? false) - ? _fromJson!(_prefs!.getString(_key)! as Map) + ? _fromJson!(jsonDecode(_prefs!.getString(_key)!)) : null, } as T?;