File tree Expand file tree Collapse file tree 4 files changed +16
-2
lines changed
packages/shared_preferences/shared_preferences Expand file tree Collapse file tree 4 files changed +16
-2
lines changed Original file line number Diff line number Diff line change
1
+ ## 2.0.0-nullsafety.1
2
+
3
+ * Fix crash when list string's type is dynamic.
4
+
1
5
## 2.0.0-nullsafety
2
6
3
7
* Migrate to null-safety.
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ class SharedPreferences {
107
107
/// Reads a set of string values from persistent storage, throwing an
108
108
/// exception if it's not a string set.
109
109
List <String >? getStringList (String key) {
110
- List <Object >? list = _preferenceCache[key] as List <Object >? ;
110
+ List <dynamic >? list = _preferenceCache[key] as List <dynamic >? ;
111
111
if (list != null && list is ! List <String >) {
112
112
list = list.cast <String >().toList ();
113
113
_preferenceCache[key] = list;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: shared_preferences
2
2
description : Flutter plugin for reading and writing simple key-value pairs.
3
3
Wraps NSUserDefaults on iOS and SharedPreferences on Android.
4
4
homepage : https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences
5
- version : 2.0.0-nullsafety
5
+ version : 2.0.0-nullsafety.1
6
6
7
7
flutter :
8
8
plugin :
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ void main() {
39
39
40
40
tearDown (() async {
41
41
await preferences.clear ();
42
+ await store.clear ();
42
43
});
43
44
44
45
test ('reading' , () async {
@@ -156,6 +157,15 @@ void main() {
156
157
expect (await first, await second);
157
158
});
158
159
160
+ test ('string list type is dynamic (usually from method channel)' , () async {
161
+ SharedPreferences .setMockInitialValues (< String , Object > {
162
+ 'dynamic_list' : < dynamic > ['1' , '2' ]
163
+ });
164
+ final SharedPreferences prefs = await SharedPreferences .getInstance ();
165
+ final List <String >? value = prefs.getStringList ('dynamic_list' );
166
+ expect (value, < String > ['1' , '2' ]);
167
+ });
168
+
159
169
group ('mocking' , () {
160
170
const String _key = 'dummy' ;
161
171
const String _prefixedKey = 'flutter.' + _key;
You can’t perform that action at this time.
0 commit comments