Skip to content

Commit 1b56cde

Browse files
[shared_preferences] Switch to Kotlin Pigeon (flutter#11661)
Replaces the Java Pigeon generator with the Kotlin Pigeon generator, and updates API signatures and number handling for Kotlin/Java generator differences. Part of flutter#158287 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 5571d4f commit 1b56cde

10 files changed

Lines changed: 829 additions & 864 deletions

File tree

‎packages/shared_preferences/shared_preferences_android/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.4.26
2+
3+
* Updates internal implementation to use Kotlin Pigeon.
4+
15
## 2.4.25
26

37
* Bumps the test-dependencies group across 2 directories with 1 update.

‎packages/shared_preferences/shared_preferences_android/android/src/main/java/io/flutter/plugins/sharedpreferences/LegacySharedPreferencesPlugin.java‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import androidx.annotation.VisibleForTesting;
1414
import io.flutter.embedding.engine.plugins.FlutterPlugin;
1515
import io.flutter.plugin.common.BinaryMessenger;
16-
import io.flutter.plugins.sharedpreferences.Messages.SharedPreferencesApi;
1716
import java.io.ByteArrayInputStream;
1817
import java.io.ByteArrayOutputStream;
1918
import java.io.IOException;
@@ -56,7 +55,7 @@ public LegacySharedPreferencesPlugin() {
5655
private void setUp(@NonNull BinaryMessenger messenger, @NonNull Context context) {
5756
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
5857
try {
59-
SharedPreferencesApi.setUp(messenger, this);
58+
SharedPreferencesApi.Companion.setUp(messenger, this);
6059
} catch (Exception ex) {
6160
Log.e(TAG, "Received exception while setting up SharedPreferencesPlugin", ex);
6261
}
@@ -69,16 +68,16 @@ public void onAttachedToEngine(@NonNull FlutterPlugin.FlutterPluginBinding bindi
6968

7069
@Override
7170
public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
72-
SharedPreferencesApi.setUp(binding.getBinaryMessenger(), null);
71+
SharedPreferencesApi.Companion.setUp(binding.getBinaryMessenger(), null);
7372
}
7473

7574
@Override
76-
public @NonNull Boolean setBool(@NonNull String key, @NonNull Boolean value) {
75+
public boolean setBool(@NonNull String key, boolean value) {
7776
return preferences.edit().putBoolean(key, value).commit();
7877
}
7978

8079
@Override
81-
public @NonNull Boolean setString(@NonNull String key, @NonNull String value) {
80+
public boolean setString(@NonNull String key, @NonNull String value) {
8281
// TODO (tarrinneal): Move this string prefix checking logic to dart code and make it an
8382
// Argument Error.
8483
if (value.startsWith(LIST_IDENTIFIER)
@@ -92,31 +91,31 @@ public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding bin
9291
}
9392

9493
@Override
95-
public @NonNull Boolean setInt(@NonNull String key, @NonNull Long value) {
94+
public boolean setInt(@NonNull String key, long value) {
9695
return preferences.edit().putLong(key, value).commit();
9796
}
9897

9998
@Override
100-
public @NonNull Boolean setDouble(@NonNull String key, @NonNull Double value) {
99+
public boolean setDouble(@NonNull String key, double value) {
101100
String doubleValueStr = Double.toString(value);
102101
return preferences.edit().putString(key, DOUBLE_PREFIX + doubleValueStr).commit();
103102
}
104103

105104
@Override
106-
public @NonNull Boolean remove(@NonNull String key) {
105+
public boolean remove(@NonNull String key) {
107106
return preferences.edit().remove(key).commit();
108107
}
109108

110109
@Override
111-
public @NonNull Boolean setEncodedStringList(@NonNull String key, @NonNull String value)
110+
public boolean setEncodedStringList(@NonNull String key, @NonNull String value)
112111
throws RuntimeException {
113112
return preferences.edit().putString(key, value).commit();
114113
}
115114

116115
// Deprecated, for testing purposes only.
117116
@Deprecated
118117
@Override
119-
public @NonNull Boolean setDeprecatedStringList(@NonNull String key, @NonNull List<String> value)
118+
public boolean setDeprecatedStringList(@NonNull String key, @NonNull List<String> value)
120119
throws RuntimeException {
121120
return preferences.edit().putString(key, LIST_IDENTIFIER + listEncoder.encode(value)).commit();
122121
}
@@ -129,7 +128,7 @@ public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding bin
129128
}
130129

131130
@Override
132-
public @NonNull Boolean clear(@NonNull String prefix, @Nullable List<String> allowList)
131+
public boolean clear(@NonNull String prefix, @Nullable List<String> allowList)
133132
throws RuntimeException {
134133
SharedPreferences.Editor clearEditor = preferences.edit();
135134
Map<String, ?> allPrefs = preferences.getAll();

0 commit comments

Comments
 (0)