2023-05-03 15:55:34 -04:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:contacts_plus_plus/models/settings.dart';
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsClient {
|
|
|
|
static const String _settingsKey = "settings";
|
|
|
|
static const _storage = FlutterSecureStorage();
|
2023-05-05 10:39:40 -04:00
|
|
|
Settings _currentSettings = Settings();
|
2023-05-03 15:55:34 -04:00
|
|
|
|
|
|
|
Settings get currentSettings => _currentSettings;
|
|
|
|
|
|
|
|
Future<void> loadSettings() async {
|
|
|
|
final data = await _storage.read(key: _settingsKey);
|
|
|
|
if (data == null) return;
|
2023-05-07 09:01:01 -04:00
|
|
|
_currentSettings = Settings.fromMap(jsonDecode(data));
|
2023-05-03 15:55:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> changeSettings(Settings newSettings) async {
|
|
|
|
_currentSettings = newSettings;
|
|
|
|
await _storage.write(key: _settingsKey, value: jsonEncode(newSettings.toMap()));
|
|
|
|
}
|
|
|
|
}
|