-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[shared_preferences] update List<String> encode/decode #8335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e772224
089d11d
29f3662
c0c08df
2ef0a01
bad5268
7a013b1
2c10fb7
614cbe4
e622f04
d317354
79ebe43
3a45c25
a49fb9f
e1f8fab
96d129b
e89421c
88ce597
7e28547
1cdce8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,8 @@ import kotlinx.coroutines.runBlocking | |
|
|
||
| const val TAG = "SharedPreferencesPlugin" | ||
| const val SHARED_PREFERENCES_NAME = "FlutterSharedPreferences" | ||
| // All identifiers must match the LegacySharedPreferencesPlugin.java file, as well as the | ||
| // strings.dart file. | ||
| const val LIST_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu" | ||
| const val JSON_LIST_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu!" | ||
|
||
| const val DOUBLE_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu" | ||
|
|
@@ -411,10 +413,13 @@ internal fun preferencesFilter(key: String, value: Any?, allowList: Set<String>? | |
| /** Transforms preferences that are stored as Strings back to original type. */ | ||
| internal fun transformPref(value: Any?, listEncoder: SharedPreferencesListEncoder): Any? { | ||
| if (value is String) { | ||
| if (value.startsWith(JSON_LIST_PREFIX)) { | ||
| return value | ||
| } else if (value.startsWith(LIST_PREFIX)) { | ||
| return listEncoder.decode(value.substring(LIST_PREFIX.length)) | ||
| if (value.startsWith(LIST_PREFIX)) { | ||
| // The newer JSON-encoded lists use an extended prefix to distinguish them. | ||
| if (value.startsWith(JSON_LIST_PREFIX)) { | ||
| return value | ||
| } else { | ||
| return listEncoder.decode(value.substring(LIST_PREFIX.length)) | ||
| } | ||
| } else if (value.startsWith(DOUBLE_PREFIX)) { | ||
| return value.substring(DOUBLE_PREFIX.length).toDouble() | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.