Revert "[shared_preferences] update List<String> encode/decode (#8335)"
This reverts commit f7efc2b67a869ccbb40545e6d8bf5941195dcefa.
diff --git a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md
index 0e2bd32..197baba 100644
--- a/packages/shared_preferences/shared_preferences_android/CHANGELOG.md
+++ b/packages/shared_preferences/shared_preferences_android/CHANGELOG.md
@@ -1,7 +1,3 @@
-## 2.4.3
-
-* Migrates `List<String>` value encoding to JSON.
-
## 2.4.2
* Bumps gradle-plugin to 2.1.0.
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java b/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java
index 4e9ae85..24bfb50 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java
+++ b/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java
@@ -25,22 +25,18 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Set;
/** LegacySharedPreferencesPlugin */
public class LegacySharedPreferencesPlugin implements FlutterPlugin, SharedPreferencesApi {
private static final String TAG = "SharedPreferencesPlugin";
private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences";
- // All identifiers must match the SharedPreferencesPlugin.kt file, as well as the strings.dart file.
private static final String LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu";
- // The symbol `!` was chosen as it cannot be created by the base 64 encoding used with LIST_IDENTIFIER.
- private static final String JSON_LIST_IDENTIFIER = LIST_IDENTIFIER + "!";
private static final String BIG_INTEGER_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy";
private static final String DOUBLE_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu";
private SharedPreferences preferences;
- private final SharedPreferencesListEncoder listEncoder;
+ private SharedPreferencesListEncoder listEncoder;
public LegacySharedPreferencesPlugin() {
this(new ListEncoder());
@@ -104,15 +100,7 @@
}
@Override
- public @NonNull Boolean setEncodedStringList(@NonNull String key, @NonNull String value)
- throws RuntimeException {
- return preferences.edit().putString(key, value).commit();
- }
-
- // Deprecated, for testing purposes only.
- @Deprecated
- @Override
- public @NonNull Boolean setDeprecatedStringList(@NonNull String key, @NonNull List<String> value)
+ public @NonNull Boolean setStringList(@NonNull String key, @NonNull List<String> value)
throws RuntimeException {
return preferences.edit().putString(key, LIST_IDENTIFIER + listEncoder.encode(value)).commit();
}
@@ -143,13 +131,14 @@
// Gets all shared preferences, filtered to only those set with the given prefix.
// Optionally filtered also to only those items in the optional [allowList].
+ @SuppressWarnings("unchecked")
private @NonNull Map<String, Object> getAllPrefs(
@NonNull String prefix, @Nullable Set<String> allowList) throws RuntimeException {
Map<String, ?> allPrefs = preferences.getAll();
Map<String, Object> filteredPrefs = new HashMap<>();
for (String key : allPrefs.keySet()) {
if (key.startsWith(prefix) && (allowList == null || allowList.contains(key))) {
- filteredPrefs.put(key, transformPref(key, Objects.requireNonNull(allPrefs.get(key))));
+ filteredPrefs.put(key, transformPref(key, allPrefs.get(key)));
}
}
@@ -160,13 +149,7 @@
if (value instanceof String) {
String stringValue = (String) value;
if (stringValue.startsWith(LIST_IDENTIFIER)) {
- // The JSON-encoded lists use an extended prefix to distinguish them from
- // lists that are encoded on the platform.
- if (stringValue.startsWith(JSON_LIST_IDENTIFIER)) {
- return value;
- } else {
- return listEncoder.decode(stringValue.substring(LIST_IDENTIFIER.length()));
- }
+ return listEncoder.decode(stringValue.substring(LIST_IDENTIFIER.length()));
} else if (stringValue.startsWith(BIG_INTEGER_PREFIX)) {
// TODO (tarrinneal): Remove all BigInt code.
// https://github.com/flutter/flutter/issues/124420
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/Messages.java b/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/Messages.java
index 8ea865c..4041ad9 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/Messages.java
+++ b/packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/Messages.java
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Autogenerated from Pigeon (v22.7.2), do not edit directly.
+// Autogenerated from Pigeon (v16.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
package io.flutter.plugins.sharedpreferences;
@@ -13,8 +13,6 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.common.StandardMessageCodec;
-import java.io.ByteArrayOutputStream;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -41,7 +39,7 @@
@NonNull
protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
- ArrayList<Object> errorList = new ArrayList<>(3);
+ ArrayList<Object> errorList = new ArrayList<Object>(3);
if (exception instanceof FlutterError) {
FlutterError error = (FlutterError) exception;
errorList.add(error.code);
@@ -55,28 +53,6 @@
}
return errorList;
}
-
- private static class PigeonCodec extends StandardMessageCodec {
- public static final PigeonCodec INSTANCE = new PigeonCodec();
-
- private PigeonCodec() {}
-
- @Override
- protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
- switch (type) {
- default:
- return super.readValueOfType(type, buffer);
- }
- }
-
- @Override
- protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
- {
- super.writeValue(stream, value);
- }
- }
- }
-
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface SharedPreferencesApi {
/** Removes property from shared preferences data set. */
@@ -96,14 +72,7 @@
Boolean setDouble(@NonNull String key, @NonNull Double value);
/** Adds property to shared preferences data set of type List<String>. */
@NonNull
- Boolean setEncodedStringList(@NonNull String key, @NonNull String value);
- /**
- * Adds property to shared preferences data set of type List<String>.
- *
- * <p>Deprecated, this is only here for testing purposes.
- */
- @NonNull
- Boolean setDeprecatedStringList(@NonNull String key, @NonNull List<String> value);
+ Boolean setStringList(@NonNull String key, @NonNull List<String> value);
/** Removes all properties from shared preferences data set with matching prefix. */
@NonNull
Boolean clear(@NonNull String prefix, @Nullable List<String> allowList);
@@ -113,7 +82,7 @@
/** The codec used by SharedPreferencesApi. */
static @NonNull MessageCodec<Object> getCodec() {
- return PigeonCodec.INSTANCE;
+ return new StandardMessageCodec();
}
/**
* Sets up an instance of `SharedPreferencesApi` to handle messages through the
@@ -121,34 +90,26 @@
*/
static void setUp(
@NonNull BinaryMessenger binaryMessenger, @Nullable SharedPreferencesApi api) {
- setUp(binaryMessenger, "", api);
- }
-
- static void setUp(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull String messageChannelSuffix,
- @Nullable SharedPreferencesApi api) {
- messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix;
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.remove"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.remove",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
try {
Boolean output = api.remove(keyArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -161,14 +122,13 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setBool"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setBool",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
Boolean valueArg = (Boolean) args.get(1);
@@ -176,7 +136,8 @@
Boolean output = api.setBool(keyArg, valueArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -189,14 +150,13 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setString"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setString",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
String valueArg = (String) args.get(1);
@@ -204,7 +164,8 @@
Boolean output = api.setString(keyArg, valueArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -217,22 +178,23 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setInt"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setInt",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
- Long valueArg = (Long) args.get(1);
+ Number valueArg = (Number) args.get(1);
try {
- Boolean output = api.setInt(keyArg, valueArg);
+ Boolean output =
+ api.setInt(keyArg, (valueArg == null) ? null : valueArg.longValue());
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -245,14 +207,13 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDouble"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDouble",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
Double valueArg = (Double) args.get(1);
@@ -260,7 +221,8 @@
Boolean output = api.setDouble(keyArg, valueArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -273,50 +235,22 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setEncodedStringList"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setStringList",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
- ArrayList<Object> args = (ArrayList<Object>) message;
- String keyArg = (String) args.get(0);
- String valueArg = (String) args.get(1);
- try {
- Boolean output = api.setEncodedStringList(keyArg, valueArg);
- wrapped.add(0, output);
- } catch (Throwable exception) {
- wrapped = wrapError(exception);
- }
- reply.reply(wrapped);
- });
- } else {
- channel.setMessageHandler(null);
- }
- }
- {
- BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
- BasicMessageChannel<Object> channel =
- new BasicMessageChannel<>(
- binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDeprecatedStringList"
- + messageChannelSuffix,
- getCodec(),
- taskQueue);
- if (api != null) {
- channel.setMessageHandler(
- (message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String keyArg = (String) args.get(0);
List<String> valueArg = (List<String>) args.get(1);
try {
- Boolean output = api.setDeprecatedStringList(keyArg, valueArg);
+ Boolean output = api.setStringList(keyArg, valueArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -329,14 +263,13 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.clear"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.clear",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String prefixArg = (String) args.get(0);
List<String> allowListArg = (List<String>) args.get(1);
@@ -344,7 +277,8 @@
Boolean output = api.clear(prefixArg, allowListArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
@@ -357,14 +291,13 @@
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll"
- + messageChannelSuffix,
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll",
getCodec(),
taskQueue);
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
- ArrayList<Object> wrapped = new ArrayList<>();
+ ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
String prefixArg = (String) args.get(0);
List<String> allowListArg = (List<String>) args.get(1);
@@ -372,7 +305,8 @@
Map<String, Object> output = api.getAll(prefixArg, allowListArg);
wrapped.add(0, output);
} catch (Throwable exception) {
- wrapped = wrapError(exception);
+ ArrayList<Object> wrappedError = wrapError(exception);
+ wrapped = wrappedError;
}
reply.reply(wrapped);
});
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/MessagesAsync.g.kt b/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/MessagesAsync.g.kt
index 44c37ba..6855bad 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/MessagesAsync.g.kt
+++ b/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/MessagesAsync.g.kt
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Autogenerated from Pigeon (v22.7.2), do not edit directly.
+// Autogenerated from Pigeon (v22.6.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
@@ -95,17 +95,7 @@
/** Adds property to shared preferences data set of type double. */
fun setDouble(key: String, value: Double, options: SharedPreferencesPigeonOptions)
/** Adds property to shared preferences data set of type List<String>. */
- fun setEncodedStringList(key: String, value: String, options: SharedPreferencesPigeonOptions)
- /**
- * Adds property to shared preferences data set of type List<String>.
- *
- * Deprecated, this is only here for testing purposes.
- */
- fun setDeprecatedStringList(
- key: String,
- value: List<String>,
- options: SharedPreferencesPigeonOptions
- )
+ fun setStringList(key: String, value: List<String>, options: SharedPreferencesPigeonOptions)
/** Gets individual String value stored with [key], if any. */
fun getString(key: String, options: SharedPreferencesPigeonOptions): String?
/** Gets individual void value stored with [key], if any. */
@@ -115,12 +105,7 @@
/** Gets individual int value stored with [key], if any. */
fun getInt(key: String, options: SharedPreferencesPigeonOptions): Long?
/** Gets individual List<String> value stored with [key], if any. */
- fun getPlatformEncodedStringList(
- key: String,
- options: SharedPreferencesPigeonOptions
- ): List<String>?
- /** Gets individual List<String> value stored with [key], if any. */
- fun getStringList(key: String, options: SharedPreferencesPigeonOptions): String?
+ fun getStringList(key: String, options: SharedPreferencesPigeonOptions): List<String>?
/** Removes all properties from shared preferences data set with matching prefix. */
fun clear(allowList: List<String>?, options: SharedPreferencesPigeonOptions)
/** Gets all properties from shared preferences data set with matching prefix. */
@@ -256,34 +241,7 @@
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setEncodedStringList$separatedMessageChannelSuffix",
- codec,
- taskQueue)
- if (api != null) {
- channel.setMessageHandler { message, reply ->
- val args = message as List<Any?>
- val keyArg = args[0] as String
- val valueArg = args[1] as String
- val optionsArg = args[2] as SharedPreferencesPigeonOptions
- val wrapped: List<Any?> =
- try {
- api.setEncodedStringList(keyArg, valueArg, optionsArg)
- listOf(null)
- } catch (exception: Throwable) {
- wrapError(exception)
- }
- reply.reply(wrapped)
- }
- } else {
- channel.setMessageHandler(null)
- }
- }
- run {
- val taskQueue = binaryMessenger.makeBackgroundTaskQueue()
- val channel =
- BasicMessageChannel<Any?>(
- binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setDeprecatedStringList$separatedMessageChannelSuffix",
+ "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setStringList$separatedMessageChannelSuffix",
codec,
taskQueue)
if (api != null) {
@@ -294,7 +252,7 @@
val optionsArg = args[2] as SharedPreferencesPigeonOptions
val wrapped: List<Any?> =
try {
- api.setDeprecatedStringList(keyArg, valueArg, optionsArg)
+ api.setStringList(keyArg, valueArg, optionsArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
@@ -410,31 +368,6 @@
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
- "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.getPlatformEncodedStringList$separatedMessageChannelSuffix",
- codec,
- taskQueue)
- if (api != null) {
- channel.setMessageHandler { message, reply ->
- val args = message as List<Any?>
- val keyArg = args[0] as String
- val optionsArg = args[1] as SharedPreferencesPigeonOptions
- val wrapped: List<Any?> =
- try {
- listOf(api.getPlatformEncodedStringList(keyArg, optionsArg))
- } catch (exception: Throwable) {
- wrapError(exception)
- }
- reply.reply(wrapped)
- }
- } else {
- channel.setMessageHandler(null)
- }
- }
- run {
- val taskQueue = binaryMessenger.makeBackgroundTaskQueue()
- val channel =
- BasicMessageChannel<Any?>(
- binaryMessenger,
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.getStringList$separatedMessageChannelSuffix",
codec,
taskQueue)
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesPlugin.kt b/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesPlugin.kt
index 4587c68..e0ca35b 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesPlugin.kt
+++ b/packages/shared_preferences/shared_preferences_android/android/src/main/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesPlugin.kt
@@ -30,11 +30,7 @@
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"
-// The symbol `!` was chosen as it cannot be created by the base 64 encoding used with LIST_PREFIX.
-const val JSON_LIST_PREFIX = LIST_PREFIX + "!"
const val DOUBLE_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu"
private val Context.sharedPreferencesDataStore: DataStore<Preferences> by
@@ -107,18 +103,8 @@
}
}
- /** Adds property to data store of type List<String> as encoded String. */
- override fun setEncodedStringList(
- key: String,
- value: String,
- options: SharedPreferencesPigeonOptions
- ) {
- return runBlocking { dataStoreSetString(key, value) }
- }
-
- /** Deprecated, for testing purposes only. Adds property to data store of type List<String>. */
- @Deprecated("This is just for testing, use `setEncodedStringList`")
- override fun setDeprecatedStringList(
+ /** Adds property to data store of type List<String>. */
+ override fun setStringList(
key: String,
value: List<String>,
options: SharedPreferencesPigeonOptions
@@ -203,33 +189,9 @@
}
/** Gets StringList at [key] from data store. */
- override fun getStringList(key: String, options: SharedPreferencesPigeonOptions): String? {
- val stringValue = getString(key, options)
- stringValue?.let {
- // The JSON-encoded lists use an extended prefix to distinguish them from
- // lists that using listEncoder.
- if (stringValue.startsWith(JSON_LIST_PREFIX)) {
- return stringValue
- }
- }
- return null
- }
-
- /** Gets StringList at [key] from data store. */
- override fun getPlatformEncodedStringList(
- key: String,
- options: SharedPreferencesPigeonOptions
- ): List<String>? {
- val stringValue = getString(key, options)
- stringValue?.let {
- // The JSON-encoded lists use an extended prefix to distinguish them from
- // lists that using listEncoder.
- if (!stringValue.startsWith(JSON_LIST_PREFIX) && stringValue.startsWith(LIST_PREFIX)) {
- val value: List<*>? = transformPref(stringValue, listEncoder) as List<*>?
- return value?.filterIsInstance<String>()
- }
- }
- return null
+ override fun getStringList(key: String, options: SharedPreferencesPigeonOptions): List<String>? {
+ val value: List<*>? = transformPref(getString(key, options) as Any?, listEncoder) as List<*>?
+ return value?.filterIsInstance<String>()
}
/** Gets all properties from data store. */
@@ -316,17 +278,7 @@
}
/** Adds property to data store of type List<String>. */
- override fun setEncodedStringList(
- key: String,
- value: String,
- options: SharedPreferencesPigeonOptions
- ) {
- return createSharedPreferences(options).edit().putString(key, value).apply()
- }
-
- /** Adds property to data store of type List<String>. */
- @Deprecated("This is just for testing, use `setEncodedStringList`")
- override fun setDeprecatedStringList(
+ override fun setStringList(
key: String,
value: List<String>,
options: SharedPreferencesPigeonOptions
@@ -387,7 +339,6 @@
null
}
}
-
/** Gets double at [key] from data store. */
override fun getDouble(key: String, options: SharedPreferencesPigeonOptions): Double? {
val preferences = createSharedPreferences(options)
@@ -397,6 +348,7 @@
null
}
}
+
/** Gets String at [key] from data store. */
override fun getString(key: String, options: SharedPreferencesPigeonOptions): String? {
val preferences = createSharedPreferences(options)
@@ -408,30 +360,14 @@
}
/** Gets StringList at [key] from data store. */
- override fun getStringList(key: String, options: SharedPreferencesPigeonOptions): String? {
+ override fun getStringList(key: String, options: SharedPreferencesPigeonOptions): List<String>? {
val preferences = createSharedPreferences(options)
- if (preferences.contains(key)) {
- val value = preferences.getString(key, "")
- if (value!!.startsWith(JSON_LIST_PREFIX)) {
- return value
- }
+ return if (preferences.contains(key)) {
+ (transformPref(preferences.getString(key, ""), listEncoder) as List<*>?)?.filterIsInstance<
+ String>()
+ } else {
+ null
}
- return null
- }
-
- override fun getPlatformEncodedStringList(
- key: String,
- options: SharedPreferencesPigeonOptions
- ): List<String>? {
- val preferences = createSharedPreferences(options)
- if (preferences.contains(key)) {
- val value = preferences.getString(key, "")
- if (value!!.startsWith(LIST_PREFIX) && !value!!.startsWith(JSON_LIST_PREFIX)) {
- val transformed = transformPref(preferences.getString(key, ""), listEncoder)
- return (transformed as List<*>?)?.filterIsInstance<String>()
- }
- }
- return null
}
/** Gets all properties from data store. */
@@ -465,13 +401,7 @@
internal fun transformPref(value: Any?, listEncoder: SharedPreferencesListEncoder): Any? {
if (value is String) {
if (value.startsWith(LIST_PREFIX)) {
- // The JSON-encoded lists use an extended prefix to distinguish them from
- // lists that are encoded on the platform.
- return if (value.startsWith(JSON_LIST_PREFIX)) {
- value
- } else {
- listEncoder.decode(value.substring(LIST_PREFIX.length))
- }
+ return listEncoder.decode(value.substring(LIST_PREFIX.length))
} else if (value.startsWith(DOUBLE_PREFIX)) {
return value.substring(DOUBLE_PREFIX.length).toDouble()
}
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/test/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesTest.java b/packages/shared_preferences/shared_preferences_android/android/src/test/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesTest.java
index 2ae67ec..08bbf2f 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/test/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesTest.java
+++ b/packages/shared_preferences/shared_preferences_android/android/src/test/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesTest.java
@@ -13,7 +13,6 @@
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import java.util.Arrays;
@@ -55,17 +54,17 @@
data.put("Language", "Java");
data.put("Counter", 0L);
data.put("Pie", 3.14);
- data.put("Names", Arrays.asList("Flutter", "Dart").toString());
+ data.put("Names", Arrays.asList("Flutter", "Dart"));
data.put("NewToFlutter", false);
data.put("flutter.Language", "Java");
data.put("flutter.Counter", 0L);
data.put("flutter.Pie", 3.14);
- data.put("flutter.Names", Arrays.asList("Flutter", "Dart").toString());
+ data.put("flutter.Names", Arrays.asList("Flutter", "Dart"));
data.put("flutter.NewToFlutter", false);
data.put("prefix.Language", "Java");
data.put("prefix.Counter", 0L);
data.put("prefix.Pie", 3.14);
- data.put("prefix.Names", Arrays.asList("Flutter", "Dart").toString());
+ data.put("prefix.Names", Arrays.asList("Flutter", "Dart"));
data.put("prefix.NewToFlutter", false);
}
@@ -81,7 +80,7 @@
assertEquals(flutterData.get("flutter.Language"), "Java");
assertEquals(flutterData.get("flutter.Counter"), 0L);
assertEquals(flutterData.get("flutter.Pie"), 3.14);
- assertEquals(flutterData.get("flutter.Names"), Arrays.asList("Flutter", "Dart").toString());
+ assertEquals(flutterData.get("flutter.Names"), Arrays.asList("Flutter", "Dart"));
assertEquals(flutterData.get("flutter.NewToFlutter"), false);
Map<String, Object> allData = plugin.getAll("", null);
@@ -143,10 +142,10 @@
}
@Test
- public void setEncodedStringListSetsAndGetsString() {
+ public void setStringList() {
final String key = "Names";
- final String value = Arrays.asList("Flutter", "Dart").toString();
- plugin.setEncodedStringList(key, value);
+ final List<String> value = Arrays.asList("Flutter", "Dart");
+ plugin.setStringList(key, value);
Map<String, Object> flutterData = plugin.getAll("", null);
assertEquals(flutterData.get(key), value);
}
@@ -207,17 +206,17 @@
plugin.setString("Language", "Java");
plugin.setInt("Counter", 0L);
plugin.setDouble("Pie", 3.14);
- plugin.setEncodedStringList("Names", Arrays.asList("Flutter", "Dart").toString());
+ plugin.setStringList("Names", Arrays.asList("Flutter", "Dart"));
plugin.setBool("NewToFlutter", false);
plugin.setString("flutter.Language", "Java");
plugin.setInt("flutter.Counter", 0L);
plugin.setDouble("flutter.Pie", 3.14);
- plugin.setEncodedStringList("flutter.Names", Arrays.asList("Flutter", "Dart").toString());
+ plugin.setStringList("flutter.Names", Arrays.asList("Flutter", "Dart"));
plugin.setBool("flutter.NewToFlutter", false);
plugin.setString("prefix.Language", "Java");
plugin.setInt("prefix.Counter", 0L);
plugin.setDouble("prefix.Pie", 3.14);
- plugin.setEncodedStringList("prefix.Names", Arrays.asList("Flutter", "Dart").toString());
+ plugin.setStringList("prefix.Names", Arrays.asList("Flutter", "Dart"));
plugin.setBool("prefix.NewToFlutter", false);
}
@@ -237,7 +236,7 @@
@Override
public @NonNull SharedPreferences.Editor putStringSet(
- @NonNull String key, @Nullable Set<String> values) {
+ @NonNull String key, @NonNull Set<String> values) {
sharedPrefData.put(key, values);
return this;
}
diff --git a/packages/shared_preferences/shared_preferences_android/android/src/test/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.kt b/packages/shared_preferences/shared_preferences_android/android/src/test/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.kt
index f36b2aa..1803138 100644
--- a/packages/shared_preferences/shared_preferences_android/android/src/test/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.kt
+++ b/packages/shared_preferences/shared_preferences_android/android/src/test/kotlin/io/flutter/plugins/sharedpreferences/SharedPreferencesTest.kt
@@ -41,7 +41,7 @@
private val testDouble = 3.14159
- private val testList = JSON_LIST_PREFIX + listOf("foo", "bar").toString()
+ private val testList = listOf("foo", "bar")
private val dataStoreOptions = SharedPreferencesPigeonOptions(useDataStore = true)
private val sharedPreferencesOptions = SharedPreferencesPigeonOptions(useDataStore = false)
@@ -95,7 +95,7 @@
@Test
fun testSetAndGetStringListWithDataStore() {
val plugin = pluginSetup(dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
Assert.assertEquals(plugin.getStringList(listKey, dataStoreOptions), testList)
}
@@ -106,7 +106,7 @@
plugin.setString(stringKey, testString, dataStoreOptions)
plugin.setInt(intKey, testInt, dataStoreOptions)
plugin.setDouble(doubleKey, testDouble, dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
val keyList = plugin.getKeys(listOf(boolKey, stringKey), dataStoreOptions)
Assert.assertEquals(keyList.size, 2)
Assert.assertTrue(keyList.contains(stringKey))
@@ -120,7 +120,7 @@
plugin.setString(stringKey, testString, dataStoreOptions)
plugin.setInt(intKey, testInt, dataStoreOptions)
plugin.setDouble(doubleKey, testDouble, dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
plugin.clear(null, dataStoreOptions)
@@ -138,7 +138,7 @@
plugin.setString(stringKey, testString, dataStoreOptions)
plugin.setInt(intKey, testInt, dataStoreOptions)
plugin.setDouble(doubleKey, testDouble, dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
val all = plugin.getAll(null, dataStoreOptions)
@@ -156,7 +156,7 @@
plugin.setString(stringKey, testString, dataStoreOptions)
plugin.setInt(intKey, testInt, dataStoreOptions)
plugin.setDouble(doubleKey, testDouble, dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
plugin.clear(listOf(boolKey, stringKey), dataStoreOptions)
@@ -174,7 +174,7 @@
plugin.setString(stringKey, testString, dataStoreOptions)
plugin.setInt(intKey, testInt, dataStoreOptions)
plugin.setDouble(doubleKey, testDouble, dataStoreOptions)
- plugin.setEncodedStringList(listKey, testList, dataStoreOptions)
+ plugin.setStringList(listKey, testList, dataStoreOptions)
val all = plugin.getAll(listOf(boolKey, stringKey), dataStoreOptions)
@@ -216,7 +216,7 @@
@Test
fun testSetAndGetStringListWithSharedPreferences() {
val plugin = pluginSetup(sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
Assert.assertEquals(plugin.getStringList(listKey, sharedPreferencesOptions), testList)
}
@@ -227,7 +227,7 @@
plugin.setString(stringKey, testString, sharedPreferencesOptions)
plugin.setInt(intKey, testInt, sharedPreferencesOptions)
plugin.setDouble(doubleKey, testDouble, sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
val keyList = plugin.getKeys(listOf(boolKey, stringKey), sharedPreferencesOptions)
Assert.assertEquals(keyList.size, 2)
Assert.assertTrue(keyList.contains(stringKey))
@@ -241,7 +241,7 @@
plugin.setString(stringKey, testString, sharedPreferencesOptions)
plugin.setInt(intKey, testInt, sharedPreferencesOptions)
plugin.setDouble(doubleKey, testDouble, sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
plugin.clear(null, sharedPreferencesOptions)
@@ -259,7 +259,7 @@
plugin.setString(stringKey, testString, sharedPreferencesOptions)
plugin.setInt(intKey, testInt, sharedPreferencesOptions)
plugin.setDouble(doubleKey, testDouble, sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
val all = plugin.getAll(null, sharedPreferencesOptions)
@@ -277,7 +277,7 @@
plugin.setString(stringKey, testString, sharedPreferencesOptions)
plugin.setInt(intKey, testInt, sharedPreferencesOptions)
plugin.setDouble(doubleKey, testDouble, sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
plugin.clear(listOf(boolKey, stringKey), sharedPreferencesOptions)
@@ -295,7 +295,7 @@
plugin.setString(stringKey, testString, sharedPreferencesOptions)
plugin.setInt(intKey, testInt, sharedPreferencesOptions)
plugin.setDouble(doubleKey, testDouble, sharedPreferencesOptions)
- plugin.setEncodedStringList(listKey, testList, sharedPreferencesOptions)
+ plugin.setStringList(listKey, testList, sharedPreferencesOptions)
val all = plugin.getAll(listOf(boolKey, stringKey), sharedPreferencesOptions)
@@ -342,7 +342,7 @@
// Inject the bad pref as a string, as that is how string lists are stored internally.
plugin.setString(badListKey, badPref, dataStoreOptions)
assertThrows(ClassNotFoundException::class.java) {
- plugin.getPlatformEncodedStringList(badListKey, dataStoreOptions)
+ plugin.getStringList(badListKey, dataStoreOptions)
}
}
}
diff --git a/packages/shared_preferences/shared_preferences_android/example/integration_test/shared_preferences_test.dart b/packages/shared_preferences/shared_preferences_android/example/integration_test/shared_preferences_test.dart
index 5964205..0335b00 100644
--- a/packages/shared_preferences/shared_preferences_android/example/integration_test/shared_preferences_test.dart
+++ b/packages/shared_preferences/shared_preferences_android/example/integration_test/shared_preferences_test.dart
@@ -6,7 +6,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:shared_preferences_android/shared_preferences_android.dart';
-import 'package:shared_preferences_android/src/messages_async.g.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
import 'package:shared_preferences_platform_interface/types.dart';
@@ -494,39 +493,6 @@
expect(values[key], null);
}
});
-
- testWidgets(
- 'Platform list encoding with getPreferences can be re-added with new encoding without data loss',
- (WidgetTester _) async {
- await preferences.clearWithParameters(
- ClearParameters(
- filter: PreferencesFilter(prefix: ''),
- ),
- );
- await preferences.setValue('String', 'String', allTestValues['String']!);
- await preferences.setValue('Bool', 'Bool', allTestValues['Bool']!);
- await preferences.setValue('Int', 'Int', allTestValues['Int']!);
- await preferences.setValue('Double', 'Double', allTestValues['Double']!);
- await (preferences as SharedPreferencesAndroid)
- .api
- .setDeprecatedStringList(
- 'StringList', allTestValues['StringList']! as List<String>);
- Map<String, Object> prefs = await preferences.getAllWithParameters(
- GetAllParameters(
- filter: PreferencesFilter(prefix: ''),
- ),
- );
- expect(prefs['StringList'], allTestValues['StringList']);
- await preferences.setValue(
- 'StringList', 'StringList', prefs['StringList']!);
- prefs = await preferences.getAllWithParameters(
- GetAllParameters(
- filter: PreferencesFilter(prefix: ''),
- ),
- );
-
- expect(prefs['StringList'], allTestValues['StringList']);
- });
});
const String stringKey = 'testString';
@@ -791,80 +757,6 @@
expect(await preferences.getDouble(doubleKey, options), testDouble);
expect(await preferences.getStringList(listKey, options), testList);
});
-
- testWidgets(
- 'platform list encoding updates to JSON encoding process without data loss with $backend',
- (WidgetTester _) async {
- final SharedPreferencesAsyncAndroidOptions options =
- getOptions(useDataStore: useDataStore, fileName: 'notDefault');
- final SharedPreferencesAsyncAndroid preferences =
- getPreferences() as SharedPreferencesAsyncAndroid;
- await clearPreferences(preferences, options);
- final SharedPreferencesPigeonOptions pigeonOptions =
- preferences.convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api =
- preferences.getApiForBackend(pigeonOptions);
- await api.setDeprecatedStringList(listKey, testList, pigeonOptions);
- final List<String>? platformEncodedList =
- await preferences.getStringList(listKey, options);
- expect(platformEncodedList, testList);
- await preferences.setStringList(listKey, platformEncodedList!, options);
- expect(await preferences.getStringList(listKey, options), testList);
- });
-
- testWidgets(
- 'platform list encoding still functions with getPreferences with $backend',
- (WidgetTester _) async {
- final SharedPreferencesAsyncAndroidOptions options =
- getOptions(useDataStore: useDataStore, fileName: 'notDefault');
- final SharedPreferencesAsyncAndroid preferences =
- getPreferences() as SharedPreferencesAsyncAndroid;
- await clearPreferences(preferences, options);
- await Future.wait(<Future<void>>[
- preferences.setString(stringKey, testString, options),
- preferences.setBool(boolKey, testBool, options),
- preferences.setInt(intKey, testInt, options),
- preferences.setDouble(doubleKey, testDouble, options),
- ]);
- final SharedPreferencesPigeonOptions pigeonOptions =
- preferences.convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api =
- preferences.getApiForBackend(pigeonOptions);
- await api.setDeprecatedStringList(listKey, testList, pigeonOptions);
-
- final Map<String, Object> prefs = await preferences.getPreferences(
- const GetPreferencesParameters(filter: PreferencesFilters()),
- options);
- expect(prefs[listKey], testList);
- });
-
- testWidgets(
- 'platform list encoding with getPreferences can be re-added with new encoding without data loss with $backend',
- (WidgetTester _) async {
- final SharedPreferencesAsyncAndroidOptions options =
- getOptions(useDataStore: useDataStore, fileName: 'notDefault');
- final SharedPreferencesAsyncAndroid preferences =
- getPreferences() as SharedPreferencesAsyncAndroid;
- await clearPreferences(preferences, options);
- await Future.wait(<Future<void>>[
- preferences.setString(stringKey, testString, options),
- preferences.setBool(boolKey, testBool, options),
- preferences.setInt(intKey, testInt, options),
- preferences.setDouble(doubleKey, testDouble, options),
- ]);
- final SharedPreferencesPigeonOptions pigeonOptions =
- preferences.convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api =
- preferences.getApiForBackend(pigeonOptions);
- await api.setDeprecatedStringList(listKey, testList, pigeonOptions);
-
- final Map<String, Object> prefs = await preferences.getPreferences(
- const GetPreferencesParameters(filter: PreferencesFilters()),
- options);
- await preferences.setStringList(listKey,
- (prefs[listKey]! as List<Object?>).cast<String>(), options);
- expect(await preferences.getStringList(listKey, options), testList);
- });
});
}
diff --git a/packages/shared_preferences/shared_preferences_android/lib/src/messages.g.dart b/packages/shared_preferences/shared_preferences_android/lib/src/messages.g.dart
index b94a30e..3a00347 100644
--- a/packages/shared_preferences/shared_preferences_android/lib/src/messages.g.dart
+++ b/packages/shared_preferences/shared_preferences_android/lib/src/messages.g.dart
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Autogenerated from Pigeon (v22.7.2), do not edit directly.
+// Autogenerated from Pigeon (v16.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
@@ -18,313 +18,256 @@
);
}
-class _PigeonCodec extends StandardMessageCodec {
- const _PigeonCodec();
- @override
- void writeValue(WriteBuffer buffer, Object? value) {
- if (value is int) {
- buffer.putUint8(4);
- buffer.putInt64(value);
- } else {
- super.writeValue(buffer, value);
- }
- }
-
- @override
- Object? readValueOfType(int type, ReadBuffer buffer) {
- switch (type) {
- default:
- return super.readValueOfType(type, buffer);
- }
- }
-}
-
class SharedPreferencesApi {
/// Constructor for [SharedPreferencesApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
- SharedPreferencesApi(
- {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
- : pigeonVar_binaryMessenger = binaryMessenger,
- pigeonVar_messageChannelSuffix =
- messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : '';
- final BinaryMessenger? pigeonVar_binaryMessenger;
+ SharedPreferencesApi({BinaryMessenger? binaryMessenger})
+ : __pigeon_binaryMessenger = binaryMessenger;
+ final BinaryMessenger? __pigeon_binaryMessenger;
- static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();
-
- final String pigeonVar_messageChannelSuffix;
+ static const MessageCodec<Object?> pigeonChannelCodec =
+ StandardMessageCodec();
/// Removes property from shared preferences data set.
Future<bool> remove(String key) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.remove$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.remove';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Adds property to shared preferences data set of type bool.
Future<bool> setBool(String key, bool value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setBool$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setBool';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key, value]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Adds property to shared preferences data set of type String.
Future<bool> setString(String key, String value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setString$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setString';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key, value]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Adds property to shared preferences data set of type int.
Future<bool> setInt(String key, int value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setInt$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setInt';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key, value]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Adds property to shared preferences data set of type double.
Future<bool> setDouble(String key, double value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDouble$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDouble';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key, value]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Adds property to shared preferences data set of type List<String>.
- Future<bool> setEncodedStringList(String key, String value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setEncodedStringList$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ Future<bool> setStringList(String key, List<String?> value) async {
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setStringList';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ final List<Object?>? __pigeon_replyList =
+ await __pigeon_channel.send(<Object?>[key, value]) as List<Object?>?;
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
- }
- }
-
- /// Adds property to shared preferences data set of type List<String>.
- ///
- /// Deprecated, this is only here for testing purposes.
- Future<bool> setDeprecatedStringList(String key, List<String> value) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDeprecatedStringList$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
- BasicMessageChannel<Object?>(
- pigeonVar_channelName,
- pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
- );
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, value]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
- throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
- );
- } else if (pigeonVar_replyList[0] == null) {
- throw PlatformException(
- code: 'null-error',
- message: 'Host platform returned null value for non-null return value.',
- );
- } else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Removes all properties from shared preferences data set with matching prefix.
- Future<bool> clear(String prefix, List<String>? allowList) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.clear$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ Future<bool> clear(String prefix, List<String?>? allowList) async {
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.clear';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
+ final List<Object?>? __pigeon_replyList = await __pigeon_channel
.send(<Object?>[prefix, allowList]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as bool?)!;
+ return (__pigeon_replyList[0] as bool?)!;
}
}
/// Gets all properties from shared preferences data set with matching prefix.
- Future<Map<String, Object>> getAll(
- String prefix, List<String>? allowList) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
+ Future<Map<String?, Object?>> getAll(
+ String prefix, List<String?>? allowList) async {
+ const String __pigeon_channelName =
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll';
+ final BasicMessageChannel<Object?> __pigeon_channel =
BasicMessageChannel<Object?>(
- pigeonVar_channelName,
+ __pigeon_channelName,
pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
+ binaryMessenger: __pigeon_binaryMessenger,
);
- final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
+ final List<Object?>? __pigeon_replyList = await __pigeon_channel
.send(<Object?>[prefix, allowList]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
+ if (__pigeon_replyList == null) {
+ throw _createConnectionError(__pigeon_channelName);
+ } else if (__pigeon_replyList.length > 1) {
throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
+ code: __pigeon_replyList[0]! as String,
+ message: __pigeon_replyList[1] as String?,
+ details: __pigeon_replyList[2],
);
- } else if (pigeonVar_replyList[0] == null) {
+ } else if (__pigeon_replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
- return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!
- .cast<String, Object>();
+ return (__pigeon_replyList[0] as Map<Object?, Object?>?)!
+ .cast<String?, Object?>();
}
}
}
diff --git a/packages/shared_preferences/shared_preferences_android/lib/src/messages_async.g.dart b/packages/shared_preferences/shared_preferences_android/lib/src/messages_async.g.dart
index 09716d1..c21b49c 100644
--- a/packages/shared_preferences/shared_preferences_android/lib/src/messages_async.g.dart
+++ b/packages/shared_preferences/shared_preferences_android/lib/src/messages_async.g.dart
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Autogenerated from Pigeon (v22.7.2), do not edit directly.
+// Autogenerated from Pigeon (v22.6.1), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
@@ -190,38 +190,10 @@
}
/// Adds property to shared preferences data set of type List<String>.
- Future<void> setEncodedStringList(
- String key, String value, SharedPreferencesPigeonOptions options) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setEncodedStringList$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
- BasicMessageChannel<Object?>(
- pigeonVar_channelName,
- pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
- );
- final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
- .send(<Object?>[key, value, options]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
- throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
- );
- } else {
- return;
- }
- }
-
- /// Adds property to shared preferences data set of type List<String>.
- ///
- /// Deprecated, this is only here for testing purposes.
- Future<void> setDeprecatedStringList(String key, List<String> value,
+ Future<void> setStringList(String key, List<String> value,
SharedPreferencesPigeonOptions options) async {
final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setDeprecatedStringList$pigeonVar_messageChannelSuffix';
+ 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.setStringList$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
@@ -348,33 +320,7 @@
}
/// Gets individual List<String> value stored with [key], if any.
- Future<List<String>?> getPlatformEncodedStringList(
- String key, SharedPreferencesPigeonOptions options) async {
- final String pigeonVar_channelName =
- 'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.getPlatformEncodedStringList$pigeonVar_messageChannelSuffix';
- final BasicMessageChannel<Object?> pigeonVar_channel =
- BasicMessageChannel<Object?>(
- pigeonVar_channelName,
- pigeonChannelCodec,
- binaryMessenger: pigeonVar_binaryMessenger,
- );
- final List<Object?>? pigeonVar_replyList =
- await pigeonVar_channel.send(<Object?>[key, options]) as List<Object?>?;
- if (pigeonVar_replyList == null) {
- throw _createConnectionError(pigeonVar_channelName);
- } else if (pigeonVar_replyList.length > 1) {
- throw PlatformException(
- code: pigeonVar_replyList[0]! as String,
- message: pigeonVar_replyList[1] as String?,
- details: pigeonVar_replyList[2],
- );
- } else {
- return (pigeonVar_replyList[0] as List<Object?>?)?.cast<String>();
- }
- }
-
- /// Gets individual List<String> value stored with [key], if any.
- Future<String?> getStringList(
+ Future<List<String>?> getStringList(
String key, SharedPreferencesPigeonOptions options) async {
final String pigeonVar_channelName =
'dev.flutter.pigeon.shared_preferences_android.SharedPreferencesAsyncApi.getStringList$pigeonVar_messageChannelSuffix';
@@ -395,7 +341,7 @@
details: pigeonVar_replyList[2],
);
} else {
- return (pigeonVar_replyList[0] as String?);
+ return (pigeonVar_replyList[0] as List<Object?>?)?.cast<String>();
}
}
diff --git a/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_android.dart b/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_android.dart
index c10a3a6..67cc083 100644
--- a/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_android.dart
+++ b/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_android.dart
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:convert';
-
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
@@ -11,7 +9,6 @@
import 'messages.g.dart';
import 'shared_preferences_async_android.dart';
-import 'strings.dart';
/// The Android implementation of [SharedPreferencesStorePlatform].
///
@@ -20,11 +17,9 @@
/// Creates a new plugin implementation instance.
SharedPreferencesAndroid({
@visibleForTesting SharedPreferencesApi? api,
- }) : api = api ?? SharedPreferencesApi();
+ }) : _api = api ?? SharedPreferencesApi();
- /// The pigeon API used to send messages to the platform.
- @visibleForTesting
- final SharedPreferencesApi api;
+ final SharedPreferencesApi _api;
/// Registers this class as the default instance of [SharedPreferencesStorePlatform].
static void registerWith() {
@@ -37,23 +32,22 @@
@override
Future<bool> remove(String key) async {
- return api.remove(key);
+ return _api.remove(key);
}
@override
Future<bool> setValue(String valueType, String key, Object value) async {
switch (valueType) {
case 'String':
- return api.setString(key, value as String);
+ return _api.setString(key, value as String);
case 'Bool':
- return api.setBool(key, value as bool);
+ return _api.setBool(key, value as bool);
case 'Int':
- return api.setInt(key, value as int);
+ return _api.setInt(key, value as int);
case 'Double':
- return api.setDouble(key, value as double);
+ return _api.setDouble(key, value as double);
case 'StringList':
- return api.setEncodedStringList(
- key, '$jsonListPrefix${jsonEncode(value)}');
+ return _api.setStringList(key, value as List<String>);
}
// TODO(tarrinneal): change to ArgumentError across all platforms.
throw PlatformException(
@@ -79,7 +73,7 @@
@override
Future<bool> clearWithParameters(ClearParameters parameters) async {
final PreferencesFilter filter = parameters.filter;
- return api.clear(
+ return _api.clear(
filter.prefix,
filter.allowList?.toList(),
);
@@ -105,17 +99,7 @@
GetAllParameters parameters) async {
final PreferencesFilter filter = parameters.filter;
final Map<String?, Object?> data =
- await api.getAll(filter.prefix, filter.allowList?.toList());
- data.forEach((String? key, Object? value) {
- if (value.runtimeType == String &&
- (value! as String).startsWith(jsonListPrefix)) {
- data[key!] =
- (jsonDecode((value as String).substring(jsonListPrefix.length))
- as List<dynamic>)
- .cast<String>()
- .toList();
- }
- });
+ await _api.getAll(filter.prefix, filter.allowList?.toList());
return data.cast<String, Object>();
}
}
diff --git a/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_async_android.dart b/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_async_android.dart
index e7c30c1..2b6dcd5 100644
--- a/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_async_android.dart
+++ b/packages/shared_preferences/shared_preferences_android/lib/src/shared_preferences_async_android.dart
@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:convert';
-
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
import 'package:shared_preferences_platform_interface/types.dart';
import 'messages_async.g.dart';
-import 'strings.dart';
const String _listPrefix = 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu';
@@ -38,8 +35,7 @@
}
/// Returns a SharedPreferencesPigeonOptions for sending to platform.
- @visibleForTesting
- SharedPreferencesPigeonOptions convertOptionsToPigeonOptions(
+ SharedPreferencesPigeonOptions _convertOptionsToPigeonOptions(
SharedPreferencesOptions options) {
if (options is SharedPreferencesAsyncAndroidOptions) {
return SharedPreferencesPigeonOptions(
@@ -51,10 +47,7 @@
return SharedPreferencesPigeonOptions();
}
- /// Provides the backend (SharedPreferences or DataStore) required based on
- /// the passed in [SharedPreferencesPigeonOptions].
- @visibleForTesting
- SharedPreferencesAsyncApi getApiForBackend(
+ SharedPreferencesAsyncApi _getApiForBackend(
SharedPreferencesPigeonOptions options) {
return options.useDataStore ? _dataStoreApi : _sharedPreferencesApi;
}
@@ -66,8 +59,8 @@
) async {
final PreferencesFilters filter = parameters.filter;
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return (await api.getKeys(
filter.allowList?.toList(),
pigeonOptions,
@@ -86,8 +79,8 @@
'StorageError: This string cannot be stored as it clashes with special identifier prefixes');
}
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return api.setString(key, value, pigeonOptions);
}
@@ -99,8 +92,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return api.setInt(key, value, pigeonOptions);
}
@@ -111,8 +104,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return api.setDouble(key, value, pigeonOptions);
}
@@ -123,8 +116,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return api.setBool(key, value, pigeonOptions);
}
@@ -135,10 +128,9 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
- final String stringValue = '$jsonListPrefix${jsonEncode(value)}';
- return api.setString(key, stringValue, pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
+ return api.setStringList(key, value, pigeonOptions);
}
@override
@@ -147,8 +139,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return _convertKnownExceptions<String>(
() async => api.getString(key, pigeonOptions));
}
@@ -159,8 +151,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return _convertKnownExceptions<bool>(
() async => api.getBool(key, pigeonOptions));
}
@@ -171,8 +163,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return _convertKnownExceptions<double>(
() async => api.getDouble(key, pigeonOptions));
}
@@ -183,8 +175,8 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return _convertKnownExceptions<int>(
() async => api.getInt(key, pigeonOptions));
}
@@ -195,28 +187,12 @@
SharedPreferencesOptions options,
) async {
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
- // Request JSON encoded string list.
- final String? jsonEncodedStringList =
- await _convertKnownExceptions<String?>(
- () async => api.getStringList(key, pigeonOptions));
- if (jsonEncodedStringList != null) {
- final String jsonEncodedString =
- jsonEncodedStringList.substring(jsonListPrefix.length);
- try {
- final List<String> decodedList =
- (jsonDecode(jsonEncodedString) as List<dynamic>).cast<String>();
- return decodedList;
- } catch (e) {
- throw TypeError();
- }
- }
- // If no JSON encoded string list exists, check for platform encoded value.
- final List<String>? stringList =
- await _convertKnownExceptions<List<String>?>(
- () async => api.getPlatformEncodedStringList(key, pigeonOptions));
- return stringList?.cast<String>().toList();
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
+ // TODO(tarrinneal): Remove cast once https://github.com/flutter/flutter/issues/97848
+ // is fixed. In practice, the values will never be null, and the native implementation assumes that.
+ return _convertKnownExceptions<List<String>>(() async =>
+ (await api.getStringList(key, pigeonOptions))?.cast<String>().toList());
}
Future<T?> _convertKnownExceptions<T>(Future<T?> Function() method) async {
@@ -239,8 +215,8 @@
) async {
final PreferencesFilters filter = parameters.filter;
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
return api.clear(
filter.allowList?.toList(),
pigeonOptions,
@@ -254,19 +230,12 @@
) async {
final PreferencesFilters filter = parameters.filter;
final SharedPreferencesPigeonOptions pigeonOptions =
- convertOptionsToPigeonOptions(options);
- final SharedPreferencesAsyncApi api = getApiForBackend(pigeonOptions);
+ _convertOptionsToPigeonOptions(options);
+ final SharedPreferencesAsyncApi api = _getApiForBackend(pigeonOptions);
final Map<String?, Object?> data = await api.getAll(
filter.allowList?.toList(),
pigeonOptions,
);
- data.forEach((String? key, Object? value) {
- if (value is String && value.startsWith(jsonListPrefix)) {
- data[key!] = (jsonDecode(value.substring(jsonListPrefix.length))
- as List<dynamic>)
- .cast<String>();
- }
- });
return data.cast<String, Object>();
}
}
diff --git a/packages/shared_preferences/shared_preferences_android/lib/src/strings.dart b/packages/shared_preferences/shared_preferences_android/lib/src/strings.dart
deleted file mode 100644
index 78c3729..0000000
--- a/packages/shared_preferences/shared_preferences_android/lib/src/strings.dart
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/// String prefix for lists that are encoded on the platform.
-const String listPrefix = 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu';
-
-/// String prefix for lists that are encoded with json in dart.
-///
-/// The addition of the symbol `!` was chosen as it can't be created by the
-/// base 64 encoding used with [listPrefix].
-const String jsonListPrefix = 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu!';
-
-/// String prefix for doubles that are encoded as strings on the platform.
-const String doublePrefix = 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu';
-
-/// String prefix for big ints that are encoded as strings on the platform.
-const String bigIntPrefix = 'VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy';
diff --git a/packages/shared_preferences/shared_preferences_android/pigeons/messages.dart b/packages/shared_preferences/shared_preferences_android/pigeons/messages.dart
index 4d58583..e359c32 100644
--- a/packages/shared_preferences/shared_preferences_android/pigeons/messages.dart
+++ b/packages/shared_preferences/shared_preferences_android/pigeons/messages.dart
@@ -37,13 +37,7 @@
/// Adds property to shared preferences data set of type List<String>.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
- bool setEncodedStringList(String key, String value);
-
- /// Adds property to shared preferences data set of type List<String>.
- ///
- /// Deprecated, this is only here for testing purposes.
- @TaskQueue(type: TaskQueueType.serialBackgroundThread)
- bool setDeprecatedStringList(String key, List<String> value);
+ bool setStringList(String key, List<String> value);
/// Removes all properties from shared preferences data set with matching prefix.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
diff --git a/packages/shared_preferences/shared_preferences_android/pigeons/messages_async.dart b/packages/shared_preferences/shared_preferences_android/pigeons/messages_async.dart
index 6668004..9334123 100644
--- a/packages/shared_preferences/shared_preferences_android/pigeons/messages_async.dart
+++ b/packages/shared_preferences/shared_preferences_android/pigeons/messages_async.dart
@@ -56,17 +56,7 @@
/// Adds property to shared preferences data set of type List<String>.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
- void setEncodedStringList(
- String key,
- String value,
- SharedPreferencesPigeonOptions options,
- );
-
- /// Adds property to shared preferences data set of type List<String>.
- ///
- /// Deprecated, this is only here for testing purposes.
- @TaskQueue(type: TaskQueueType.serialBackgroundThread)
- void setDeprecatedStringList(
+ void setStringList(
String key,
List<String> value,
SharedPreferencesPigeonOptions options,
@@ -102,14 +92,7 @@
/// Gets individual List<String> value stored with [key], if any.
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
- List<String>? getPlatformEncodedStringList(
- String key,
- SharedPreferencesPigeonOptions options,
- );
-
- /// Gets individual List<String> value stored with [key], if any.
- @TaskQueue(type: TaskQueueType.serialBackgroundThread)
- String? getStringList(
+ List<String>? getStringList(
String key,
SharedPreferencesPigeonOptions options,
);
diff --git a/packages/shared_preferences/shared_preferences_android/pubspec.yaml b/packages/shared_preferences/shared_preferences_android/pubspec.yaml
index bda1bd0..e2f143a 100644
--- a/packages/shared_preferences/shared_preferences_android/pubspec.yaml
+++ b/packages/shared_preferences/shared_preferences_android/pubspec.yaml
@@ -2,7 +2,7 @@
description: Android implementation of the shared_preferences plugin
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
-version: 2.4.3
+version: 2.4.2
environment:
sdk: ^3.5.0
@@ -25,7 +25,7 @@
dev_dependencies:
flutter_test:
sdk: flutter
- pigeon: ^22.7.2
+ pigeon: ^22.6.0
topics:
- persistence
diff --git a/packages/shared_preferences/shared_preferences_android/test/shared_preferences_android_test.dart b/packages/shared_preferences/shared_preferences_android/test/shared_preferences_android_test.dart
index ce42b4b..c30fa08 100644
--- a/packages/shared_preferences/shared_preferences_android/test/shared_preferences_android_test.dart
+++ b/packages/shared_preferences/shared_preferences_android/test/shared_preferences_android_test.dart
@@ -2,13 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'dart:convert';
-
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_android/shared_preferences_android.dart';
import 'package:shared_preferences_android/src/messages.g.dart';
-import 'package:shared_preferences_android/src/strings.dart';
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
import 'package:shared_preferences_platform_interface/types.dart';
@@ -41,22 +38,11 @@
'StringList': <String>['foo', 'bar'],
};
- final Map<String, Object> allTestValuesForComparison = <String, Object>{};
+ final Map<String, Object> allTestValues = <String, Object>{};
- allTestValuesForComparison.addAll(flutterTestValues);
- allTestValuesForComparison.addAll(prefixTestValues);
- allTestValuesForComparison.addAll(nonPrefixTestValues);
-
- final Map<String, Object> allTestValuesForAddingDirectlyToCache =
- <String, Object>{...allTestValuesForComparison};
-
- final String encodedListStringValue =
- '$jsonListPrefix${jsonEncode(<String>['foo', 'bar'])}';
- allTestValuesForAddingDirectlyToCache['flutter.StringList'] =
- encodedListStringValue;
- allTestValuesForAddingDirectlyToCache['prefix.StringList'] =
- encodedListStringValue;
- allTestValuesForAddingDirectlyToCache['StringList'] = encodedListStringValue;
+ allTestValues.addAll(flutterTestValues);
+ allTestValues.addAll(prefixTestValues);
+ allTestValues.addAll(nonPrefixTestValues);
setUp(() {
api = _FakeSharedPreferencesApi();
@@ -82,8 +68,8 @@
});
test('clearWithPrefix', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
Map<String?, Object?> all = await plugin.getAllWithPrefix('prefix.');
@@ -96,8 +82,8 @@
});
test('clearWithParameters', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
Map<String?, Object?> all = await plugin.getAllWithParameters(
@@ -122,8 +108,8 @@
});
test('clearWithParameters with allow list', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
Map<String?, Object?> all = await plugin.getAllWithParameters(
@@ -160,17 +146,17 @@
});
test('getAllWithNoPrefix', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
final Map<String?, Object?> all = await plugin.getAllWithPrefix('');
expect(all.length, 15);
- expect(all, allTestValuesForComparison);
+ expect(all, allTestValues);
});
test('clearWithNoPrefix', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
Map<String?, Object?> all = await plugin.getAllWithPrefix('');
@@ -181,8 +167,8 @@
});
test('getAllWithParameters', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
final Map<String?, Object?> all = await plugin.getAllWithParameters(
GetAllParameters(
@@ -194,8 +180,8 @@
});
test('getAllWithParameters with allow list', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
final Map<String?, Object?> all = await plugin.getAllWithParameters(
GetAllParameters(
@@ -222,8 +208,7 @@
await plugin
.setValue('StringList', 'flutter.StringList', <String>['hi']),
isTrue);
- expect(api.items['flutter.StringList'],
- '$jsonListPrefix${jsonEncode(<String>['hi'])}');
+ expect(api.items['flutter.StringList'], <String>['hi']);
});
test('setValue with unsupported type', () async {
@@ -233,8 +218,8 @@
});
test('getAllWithNoPrefix', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
final Map<String?, Object?> all = await plugin.getAllWithParameters(
GetAllParameters(
@@ -242,12 +227,12 @@
),
);
expect(all.length, 15);
- expect(all, allTestValuesForComparison);
+ expect(all, allTestValues);
});
test('clearWithNoPrefix', () async {
- for (final String key in allTestValuesForAddingDirectlyToCache.keys) {
- api.items[key] = allTestValuesForAddingDirectlyToCache[key]!;
+ for (final String key in allTestValues.keys) {
+ api.items[key] = allTestValues[key]!;
}
Map<String?, Object?> all = await plugin.getAllWithParameters(
@@ -274,7 +259,7 @@
final Map<String, Object> items = <String, Object>{};
@override
- Future<Map<String, Object>> getAll(
+ Future<Map<String?, Object?>> getAll(
String prefix,
List<String?>? allowList,
) async {
@@ -282,23 +267,12 @@
if (allowList != null) {
allowSet = Set<String>.from(allowList);
}
- final Map<String, Object> filteredItems = <String, Object>{
+ return <String?, Object?>{
for (final String key in items.keys)
if (key.startsWith(prefix) &&
(allowSet == null || allowSet.contains(key)))
- key: items[key]!
+ key: items[key]
};
- filteredItems.forEach((String? key, Object? value) {
- if (value.runtimeType == String &&
- (value! as String).startsWith(jsonListPrefix)) {
- filteredItems[key!] =
- (jsonDecode((value as String).substring(jsonListPrefix.length))
- as List<dynamic>)
- .cast<String>()
- .toList();
- }
- });
- return filteredItems;
}
@override
@@ -343,22 +317,8 @@
}
@override
- Future<bool> setEncodedStringList(String key, String value) async {
+ Future<bool> setStringList(String key, List<String?> value) async {
items[key] = value;
return true;
}
-
- @override
- Future<bool> setDeprecatedStringList(String key, List<String> value) async {
- items[key] = value;
- return true;
- }
-
- @override
- // ignore: non_constant_identifier_names
- BinaryMessenger? get pigeonVar_binaryMessenger => throw UnimplementedError();
-
- @override
- // ignore: non_constant_identifier_names
- String get pigeonVar_messageChannelSuffix => throw UnimplementedError();
}
diff --git a/packages/shared_preferences/shared_preferences_android/test/shared_preferences_async_test.dart b/packages/shared_preferences/shared_preferences_android/test/shared_preferences_async_test.dart
index 404c043..fd2907e 100755
--- a/packages/shared_preferences/shared_preferences_android/test/shared_preferences_async_test.dart
+++ b/packages/shared_preferences/shared_preferences_android/test/shared_preferences_async_test.dart
@@ -4,13 +4,10 @@
// ignore_for_file: non_constant_identifier_names
-import 'dart:convert';
-
import 'package:flutter/src/services/binary_messenger.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_android/shared_preferences_android.dart';
import 'package:shared_preferences_android/src/messages_async.g.dart';
-import 'package:shared_preferences_android/src/strings.dart';
import 'package:shared_preferences_platform_interface/types.dart';
void main() {
@@ -86,10 +83,7 @@
getPreferences(useDataStore);
await preferences.setStringList(listKey, testList, emptyOptions);
- final List<String>? response =
- await preferences.getStringList(listKey, emptyOptions);
-
- expect(response, testList);
+ expect(await preferences.getStringList(listKey, emptyOptions), testList);
});
test('getPreferences with $backend', () async {
@@ -298,13 +292,7 @@
}
@override
- Future<String?> getStringList(
- String key, SharedPreferencesPigeonOptions options) async {
- return items[key] as String?;
- }
-
- @override
- Future<List<String>?> getPlatformEncodedStringList(
+ Future<List<String>?> getStringList(
String key, SharedPreferencesPigeonOptions options) async {
return items[key] as List<String>?;
}
@@ -338,14 +326,7 @@
}
@override
- Future<bool> setEncodedStringList(
- String key, String value, SharedPreferencesPigeonOptions options) async {
- items[key] = '$jsonListPrefix${jsonEncode(value)}';
- return true;
- }
-
- @override
- Future<bool> setDeprecatedStringList(String key, List<String> value,
+ Future<bool> setStringList(String key, List<String?> value,
SharedPreferencesPigeonOptions options) async {
items[key] = value;
return true;