init: rough companion app stub
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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((_) {});
|
||||
}
|
||||
Reference in New Issue
Block a user