我有在 native 端创建共享首选项的代码。 当我向它添加一个值时,我无法从我的 Dart 代码中获取它。 只有在我重新启动应用程序或重新编译后,我才能访问该值。
为什么会这样?
最佳答案
我假设您使用 shared_preferences
package ,这caches the shared preferences internally .
您可以在共享首选项实例上调用 reload()
以从主机平台获取最新值:
var sharedPrefs = await SharedPreferences.getInstance();
await sharedPrefs.reload();
// sharedPrefs now contains the latest entries
关于flutter - 我无法从 Flutter 应用程序检索在 native 代码中创建的 SharedPreference 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57222417/