- 在首页添加 Wakatime 卡片和相关功能 - 在设置页面添加 Wakatime API Token 配置 - 更新 auth_service 以支持 Wakatime 认证 - 添加 fl_chart 依赖用于 Wakatime 数据图表展示 - 更新 flutter_lints 版本到 2.0.0
64 lines
2.1 KiB
Dart
64 lines
2.1 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;
|
|
final 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 leetcodeUserSlug = await _storage.read(key: 'leetcode_user_slug');
|
|
final giteaToken = await _storage.read(key: 'gitea_token');
|
|
final giteaUserName = await _storage.read(key: 'gitea_username');
|
|
final kodboxToken = await _storage.read(key: 'kodbox_token');
|
|
final githubUserName = await _storage.read(key: 'github_username');
|
|
final githubToken = await _storage.read(key: 'github_token');
|
|
final wakatimeToken = await _storage.read(key: 'wakatime_token');
|
|
|
|
if (leetcodeCookie != null) {
|
|
_credentials['leetcode_cookie'] = leetcodeCookie;
|
|
}
|
|
if (leetcodeUserSlug != null) {
|
|
_credentials['leetcode_user_slug'] = leetcodeUserSlug;
|
|
}
|
|
if (giteaToken != null) {
|
|
_credentials['gitea_token'] = giteaToken;
|
|
}
|
|
if (giteaUserName != null) {
|
|
_credentials['gitea_username'] = giteaUserName;
|
|
}
|
|
if (kodboxToken != null) {
|
|
_credentials['kodbox_token'] = kodboxToken;
|
|
}
|
|
if (githubUserName != null) {
|
|
_credentials['github_username'] = githubUserName;
|
|
}
|
|
if (githubToken != null) {
|
|
_credentials['github_token'] = githubToken;
|
|
}
|
|
if (wakatimeToken != null) {
|
|
_credentials['wakatime_token'] = wakatimeToken;
|
|
}
|
|
_isAuthenticated = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
await _storage.deleteAll();
|
|
_credentials.clear();
|
|
_isAuthenticated = false;
|
|
notifyListeners();
|
|
}
|
|
}
|