cpd_2022_zi/lib/service/settings_service.dart

22 lines
825 B
Dart

import 'package:shared_preferences/shared_preferences.dart';
class SettingsService {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
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));
//Add other setters and getters if needed
//other possible SharedPreferences Types: Int, Bool, Double, StringList
//see https://pub.dev/packages/shared_preferences
}