2023-01-20 01:37:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-16 16:06:11 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-12-30 16:07:56 +00:00
|
|
|
|
2023-01-20 01:37:35 +00:00
|
|
|
import '../utils/theme_mode_extensions.dart';
|
|
|
|
|
2022-12-30 16:07:56 +00:00
|
|
|
class SettingsService extends ChangeNotifier {
|
2023-01-16 16:06:11 +00:00
|
|
|
late final SharedPreferences _prefs;
|
|
|
|
var _initialized = false;
|
|
|
|
|
|
|
|
SettingsService();
|
|
|
|
|
|
|
|
var _lowBandwidthMode = false;
|
2022-12-30 16:07:56 +00:00
|
|
|
|
|
|
|
bool get lowBandwidthMode => _lowBandwidthMode;
|
|
|
|
|
|
|
|
set lowBandwidthMode(bool value) {
|
|
|
|
_lowBandwidthMode = value;
|
2023-01-16 16:06:11 +00:00
|
|
|
_prefs.setBool(_lowBandwidthModeKey, _lowBandwidthMode);
|
2022-12-30 16:07:56 +00:00
|
|
|
notifyListeners();
|
|
|
|
}
|
2023-01-16 16:06:11 +00:00
|
|
|
|
2023-01-20 01:37:35 +00:00
|
|
|
var _themeMode = ThemeMode.system;
|
|
|
|
|
|
|
|
ThemeMode get themeMode => _themeMode;
|
|
|
|
|
|
|
|
set themeMode(ThemeMode mode) {
|
|
|
|
_themeMode = mode;
|
|
|
|
_prefs.setString(_themeModeKey, _themeMode.name);
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2023-01-16 16:06:11 +00:00
|
|
|
Future<void> initialize() async {
|
|
|
|
if (_initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_prefs = await SharedPreferences.getInstance();
|
|
|
|
_lowBandwidthMode = _prefs.getBool(_lowBandwidthModeKey) ?? false;
|
2023-01-20 01:37:35 +00:00
|
|
|
_themeMode = ThemeModeExtensions.parse(_prefs.getString(_themeModeKey));
|
2023-01-16 16:06:11 +00:00
|
|
|
_initialized = true;
|
|
|
|
}
|
2022-12-30 16:07:56 +00:00
|
|
|
}
|
2023-01-16 16:06:11 +00:00
|
|
|
|
|
|
|
const _lowBandwidthModeKey = 'LowBandwidthMode';
|
2023-01-20 01:37:35 +00:00
|
|
|
const _themeModeKey = 'ThemeMode';
|