Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I cannot retrieve SharedPreference value created in native code from Flutter app

Tags:

flutter

dart

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?

like image 504
Saeiddjawadi Avatar asked Sep 22 '26 19:09

Saeiddjawadi


1 Answers

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
like image 188
Marcel Avatar answered Sep 25 '26 14:09

Marcel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!