Initial commit: 91dj android client dev_1.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import 'package:analytics_sdk/enum/user_type_enum.dart';
|
||||
|
||||
/// 全局用户管理器
|
||||
/// 负责管理用户类型信息,支持用户类型更新和登出操作
|
||||
class UserManager {
|
||||
static final UserManager instance = UserManager._internal();
|
||||
|
||||
factory UserManager() => instance;
|
||||
|
||||
UserManager._internal();
|
||||
|
||||
/// 当前用户类型:normal、vip 等
|
||||
String _userType = UserTypeEnum.normal.label;
|
||||
|
||||
String get userType => _userType;
|
||||
|
||||
static String normalizeUserType(String? value) {
|
||||
return value?.trim().toLowerCase() == UserTypeEnum.vip.label
|
||||
? UserTypeEnum.vip.label
|
||||
: UserTypeEnum.normal.label;
|
||||
}
|
||||
|
||||
/// 更新用户类型(登录、升级会员、切换账号时调用)
|
||||
void updateUserType(String newType) {
|
||||
final normalized = normalizeUserType(newType);
|
||||
if (_userType != normalized) {
|
||||
_userType = normalized;
|
||||
}
|
||||
}
|
||||
|
||||
/// 登出
|
||||
void logout() {
|
||||
_userType = UserTypeEnum.normal.label; // 或 'guest',根据业务决定
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user