29 lines
1.1 KiB
Dart
29 lines
1.1 KiB
Dart
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
const _storage = FlutterSecureStorage();
|
|
|
|
/// Manages login details
|
|
class LoginManager {
|
|
/// Checks if user has saved login details
|
|
static Future<bool> get hasSavedLogin async {
|
|
return (await _storage.containsKey(key: "sub_user")) &&
|
|
(await _storage.containsKey(key: "sub_pass")) &&
|
|
(await _storage.containsKey(key: "sub_url"));
|
|
}
|
|
|
|
/// Stores log in details into secure storage
|
|
static Future<void> saveDetails(String user, String pass, String url) async {
|
|
await _storage.write(key: "sub_user", value: user);
|
|
await _storage.write(key: "sub_pass", value: pass);
|
|
await _storage.write(key: "sub_url", value: url);
|
|
}
|
|
|
|
/// Returns log in details from secure storage
|
|
static Future<Map<String, String>?> getDetails() async {
|
|
final user = await _storage.read(key: "sub_user");
|
|
final pass = await _storage.read(key: "sub_pass");
|
|
final url = await _storage.read(key: "sub_url");
|
|
if (user == null || pass == null || url == null) return null;
|
|
return {"user": user, "pass": pass, "url": url};
|
|
}
|
|
}
|