-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[shared_preferences] Fix Android type mismatch regression #8512
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
`getStringList` should throw a `TypeError` if the stored value is of a different type, but the recent change to use JSON-encoded string lists regression that behavior if the stored type was a string, causing it to instead return null. This restores the previous behavior by passing extra information from Kotlin to Dart when attempting to get an enecoded string list, so that if a non-encoded-list string is found, a TypeError can be created on the Dart side. Since extra information is now being passed, the case of a legacy-encoded value is now communicated as well, so that we only have to request the legacy value if it's there, rather than always trying (which was not worth the complexity of adding extra data just for that initially, but now that we need extra data anyway, it's easy to distinguish that case). Fixes OOB regression in `shared_preferences` tests that has closed the tree.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,27 @@ class SharedPreferencesPigeonOptions { | |
| bool useDataStore; | ||
| } | ||
|
|
||
| class StringListResult { | ||
| StringListResult({ | ||
| required this.jsonEncodedValue, | ||
| required this.foundPlatformEncodedValue, | ||
| }); | ||
|
|
||
| /// The JSON-encoded stored value, or null if something else was found, in | ||
| /// which case [foundPlatformEncodedValue] will indicate its type. | ||
| String? jsonEncodedValue; | ||
|
|
||
| /// Whether value using the legacy platform-side encoding was found. | ||
| /// | ||
| /// This value is only meaningful if [jsonEncodedValue] is null. | ||
| /// - If true, the value should be fetched with | ||
| /// getPlatformEncodedStringList(...) instead. | ||
| /// - If false, an unexpected string (one without any encoding prefix) was | ||
| /// found. This will happen if a client uses getStringList with a key that | ||
| /// was used with setString. | ||
| bool foundPlatformEncodedValue; | ||
|
||
| } | ||
|
|
||
| @HostApi(dartHostTestHandler: 'TestSharedPreferencesAsyncApi') | ||
| abstract class SharedPreferencesAsyncApi { | ||
| /// Adds property to shared preferences data set of type bool. | ||
|
|
@@ -107,9 +128,9 @@ abstract class SharedPreferencesAsyncApi { | |
| SharedPreferencesPigeonOptions options, | ||
| ); | ||
|
|
||
| /// Gets individual List<String> value stored with [key], if any. | ||
| /// Gets the JSON-encoded List<String> value stored with [key], if any. | ||
| @TaskQueue(type: TaskQueueType.serialBackgroundThread) | ||
| String? getStringList( | ||
| StringListResult? getStringList( | ||
| String key, | ||
| SharedPreferencesPigeonOptions options, | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non blocking nit: would prefer "...DeprecatedStringList" over "Legacy" but this is a test so the consequence is small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to the more specific "PlatformEncoded".