Reputation: 332
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?
Upvotes: 3
Views: 340
Reputation: 9609
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
Upvotes: 3