【发布时间】:2019-03-18 15:50:48
【问题描述】:
我在 dart 中有以下函数来设置特定的布尔偏好值。
_switchPersistentNotifications() {
setState(() {
isPersistentNotificationEnabled = !isPersistentNotificationEnabled;
});
widget.preferences.setBool(
"isPersistentNotificationEnabled", isPersistentNotificationEnabled);
}
此函数设置isPersistentNotificationEnabled 首选项的值。
现在在原生 android 端,我应该使用这个共享偏好值。这是我到目前为止所做的。
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
// check if the state change notification is to be shown
if (preferences.getBoolean("flutter.isStateChangeNotificationEnabled", false)) {
showConnectionStateChangeNotification();
}
并且 if 条件永远不会被评估为 true。我还尝试使用下面的代码打印所有现有的首选项值。
Map<String, ?> allEntries = preferences.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Log.d("map values", entry.getKey() + ": " + entry.getValue().toString());
}
而且它只呈现 Android 创建的值(使用 java)。
非常感谢您在访问首选项值方面的任何帮助。 谢谢。
【问题讨论】:
标签: android flutter sharedpreferences flutter-dependencies