Load server configuration
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:moneymgr_mobile/services/api/server_api.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@ -9,3 +12,19 @@ Future<SharedPreferencesWithCache> prefs(Ref ref) =>
|
||||
SharedPreferencesWithCache.create(
|
||||
cacheOptions: const SharedPreferencesWithCacheOptions(),
|
||||
);
|
||||
|
||||
extension MoneyMgrSharedPreferences on SharedPreferencesWithCache {
|
||||
ServerConfig? serverConfig() {
|
||||
final json = getString("serverConfig");
|
||||
if (json != null) return ServerConfig.fromJson(jsonDecode(json));
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> setServerConfig(ServerConfig config) async {
|
||||
await setString("serverConfig", jsonEncode(config));
|
||||
}
|
||||
|
||||
Future<void> clearServerConfig() async {
|
||||
await remove("serverConfig");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user