2023-02-16 01:59:15 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2023-02-17 13:47:52 +01:00
|
|
|
import 'package:smoke_cess_app/models/settings.dart';
|
|
|
|
import 'package:smoke_cess_app/service/json_service.dart';
|
2023-02-16 01:59:15 +01:00
|
|
|
|
2023-02-19 14:24:39 +01:00
|
|
|
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
//access group setting which was saved in local storage
|
|
|
|
Future<String?> getGroup() {
|
|
|
|
return getStringSetting('group');
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStringSetting(String settingKey, String settingValue) =>
|
|
|
|
_prefs.then((pref) => pref.setString(settingKey, settingValue));
|
|
|
|
|
|
|
|
Future<String?> getStringSetting(String settingKey) =>
|
|
|
|
_prefs.then((pref) => pref.getString(settingKey));
|
|
|
|
|
|
|
|
void setIntSetting(String settingKey, int settingValue) =>
|
|
|
|
_prefs.then((pref) => pref.setInt(settingKey, settingValue));
|
|
|
|
|
|
|
|
Future<int?> getIntSetting(String settingKey) =>
|
|
|
|
_prefs.then((pref) => pref.getInt(settingKey));
|
|
|
|
|
|
|
|
void setStringList(String settingKey, List<String> list) =>
|
|
|
|
_prefs.then((pref) => pref.setStringList(settingKey, list));
|
|
|
|
|
|
|
|
//Add other setters and getters if needed
|
|
|
|
//other possible SharedPreferences Types: Int, Bool, Double, StringList
|
|
|
|
//see https://pub.dev/packages/shared_preferences
|
|
|
|
|
|
|
|
Future<void> loadSettings() async {
|
|
|
|
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
|
|
|
|
Settings settings = Settings.fromJson(configJSON);
|
|
|
|
print(settings.group);
|
|
|
|
saveSettings(settings);
|
|
|
|
String gruppe = (await getGroup())!;
|
|
|
|
print('Gruppe: $gruppe');
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveSettings(Settings settings) {
|
|
|
|
setStringSetting('group', settings.group);
|
|
|
|
setStringSetting('key', settings.key);
|
2023-02-16 01:59:15 +01:00
|
|
|
}
|