- 重命名和更新认证服务中的配置键名 - 在主入口文件中添加时间格式化库的初始化 - 更新设置屏幕中的配置加载和保存逻辑 - 在各个卡片组件中使用时间格式化库显示时间信息
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
class AuthService extends ChangeNotifier {
|
|
final _storage = const FlutterSecureStorage();
|
|
bool _isAuthenticated = false;
|
|
Map<String, String> _credentials = {};
|
|
|
|
bool get isAuthenticated => _isAuthenticated;
|
|
Map<String, String> get credentials => _credentials;
|
|
|
|
Future<void> saveConfigs(String key, String value) async {
|
|
await _storage.write(key: key, value: value);
|
|
_credentials[key] = value;
|
|
_isAuthenticated = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> loadConfigs() async {
|
|
final leetcodeCookie = await _storage.read(key: 'leetcode_cookie');
|
|
final giteaToken = await _storage.read(key: 'gitea_token');
|
|
final giteaUserName = await _storage.read(key: 'gitea_username');
|
|
final kodboxToken = await _storage.read(key: 'kodbox_token');
|
|
if (leetcodeCookie != null) {
|
|
_credentials['leetcode_cookie'] = leetcodeCookie;
|
|
}
|
|
if (giteaToken != null) {
|
|
_credentials['gitea_token'] = giteaToken;
|
|
}
|
|
if (giteaUserName != null) {
|
|
_credentials['gitea_username'] = giteaUserName;
|
|
}
|
|
if (kodboxToken != null) {
|
|
_credentials['kodbox_token'] = kodboxToken;
|
|
}
|
|
_isAuthenticated = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
await _storage.deleteAll();
|
|
_credentials.clear();
|
|
_isAuthenticated = false;
|
|
notifyListeners();
|
|
}
|
|
}
|