Files
companion/lib/data/sources/local/credential_store.dart
T
2026-05-07 18:35:58 +02:00

32 lines
1.0 KiB
Dart

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
typedef Credentials = ({String username, String password});
class CredentialStore {
static const _usernameKey = 'localiserd_username';
static const _passwordKey = 'localiserd_password';
final _storage = const FlutterSecureStorage();
Future<void> save(Credentials credentials) => Future.wait([
_storage.write(key: _usernameKey, value: credentials.username),
_storage.write(key: _passwordKey, value: credentials.password),
]).then((_) {});
Future<Credentials?> load() async {
final results = await Future.wait([
_storage.read(key: _usernameKey),
_storage.read(key: _passwordKey),
]);
final username = results[0];
final password = results[1];
if (username == null || password == null) return null;
return (username: username, password: password);
}
Future<void> clear() => Future.wait([
_storage.delete(key: _usernameKey),
_storage.delete(key: _passwordKey),
]).then((_) {});
}