1010import io .flutter .plugin .common .MethodChannel ;
1111import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
1212import io .flutter .plugin .common .PluginRegistry ;
13+ import java .math .BigInteger ;
1314import java .util .HashMap ;
1415import java .util .HashSet ;
1516import java .util .List ;
@@ -20,6 +21,8 @@ public class SharedPreferencesPlugin implements MethodCallHandler {
2021 private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences" ;
2122 private static final String CHANNEL_NAME = "plugins.flutter.io/shared_preferences" ;
2223
24+ private static final String BIG_INTEGER_PREFIX = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy" ;
25+
2326 private final android .content .SharedPreferences preferences ;
2427 private final android .content .SharedPreferences .Editor editor ;
2528
@@ -40,7 +43,15 @@ private Map<String, Object> getAllPrefs() {
4043 Map <String , Object > filteredPrefs = new HashMap <>();
4144 for (String key : allPrefs .keySet ()) {
4245 if (key .startsWith ("flutter." )) {
43- filteredPrefs .put (key , allPrefs .get (key ));
46+ Object value = allPrefs .get (key );
47+ if (value instanceof String ) {
48+ String stringValue = (String ) value ;
49+ if (stringValue .startsWith (BIG_INTEGER_PREFIX )) {
50+ String encoded = stringValue .substring (BIG_INTEGER_PREFIX .length ());
51+ value = new BigInteger (encoded , Character .MAX_RADIX );
52+ }
53+ }
54+ filteredPrefs .put (key , value );
4455 }
4556 }
4657 return filteredPrefs ;
@@ -59,7 +70,14 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
5970 result .success (null );
6071 break ;
6172 case "setInt" :
62- editor .putInt (key , (int ) call .argument ("value" )).apply ();
73+ Number value = call .argument ("value" );
74+ if (value instanceof BigInteger ) {
75+ BigInteger integerValue = (BigInteger ) value ;
76+ editor .putString (key , BIG_INTEGER_PREFIX + integerValue .toString (Character .MAX_RADIX ));
77+ } else {
78+ editor .putLong (key , value .longValue ());
79+ }
80+ editor .apply ();
6381 result .success (null );
6482 break ;
6583 case "setString" :
0 commit comments