feat: persist server settings

This commit is contained in:
2026-05-07 19:51:17 +02:00
parent 7186081388
commit 711c321dcf
3 changed files with 31 additions and 25 deletions
@@ -1,10 +1,14 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../../../domain/models/server_config.dart';
typedef Credentials = ({String username, String password});
class CredentialStore {
static const _usernameKey = 'localiserd_username';
static const _passwordKey = 'localiserd_password';
static const _hostKey = 'localiserd_host';
static const _portKey = 'localiserd_port';
final _storage = const FlutterSecureStorage();
@@ -24,8 +28,28 @@ class CredentialStore {
return (username: username, password: password);
}
Future<void> saveServer(ServerConfig config) => Future.wait([
_storage.write(key: _hostKey, value: config.host),
_storage.write(key: _portKey, value: config.port.toString()),
]).then((_) {});
Future<ServerConfig?> loadServer() async {
final results = await Future.wait([
_storage.read(key: _hostKey),
_storage.read(key: _portKey),
]);
final host = results[0];
final portStr = results[1];
if (host == null || portStr == null) return null;
final port = int.tryParse(portStr);
if (port == null) return null;
return ServerConfig(host: host, port: port);
}
Future<void> clear() => Future.wait([
_storage.delete(key: _usernameKey),
_storage.delete(key: _passwordKey),
_storage.delete(key: _hostKey),
_storage.delete(key: _portKey),
]).then((_) {});
}