I have code that creates a shared preference on the native side. When I add a value to it, I can not get it from my Dart code. Only after I restart the app or recompile, I can access the value.
Why does that happen?
I assume you use the shared_preferences package, which caches the shared preferences internally.
You can call reload() on your shared preferences instance to fetch the latest values from the host platform:
var sharedPrefs = await SharedPreferences.getInstance();
await sharedPrefs.reload();
// sharedPrefs now contains the latest entries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With