- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换 - 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照 - 设备策略切换后自动使本地缓存失效,避免数据不一致 - Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮 - 系统设置页引入 loading 遮罩层,防止切换开关时重复操作 - 个人资料页接入 profileController 展示真实用户信息与加载状态 - 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
54 lines
1.3 KiB
Dart
54 lines
1.3 KiB
Dart
// Freezed forwards factory parameter annotations to generated fields.
|
|
// ignore_for_file: invalid_annotation_target
|
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'profile_models.freezed.dart';
|
|
part 'profile_models.g.dart';
|
|
|
|
@freezed
|
|
class UserProfile with _$UserProfile {
|
|
const UserProfile._();
|
|
|
|
const factory UserProfile({
|
|
@JsonKey(fromJson: _idToString) required String id,
|
|
@Default('') String username,
|
|
@Default('') String nickname,
|
|
@Default('') String signature,
|
|
String? avatar,
|
|
}) = _UserProfile;
|
|
|
|
factory UserProfile.fromJson(Map<String, dynamic> json) =>
|
|
_$UserProfileFromJson(json);
|
|
|
|
String get displayName => nickname.isNotEmpty ? nickname : username;
|
|
}
|
|
|
|
String _idToString(Object? value) => value?.toString() ?? '';
|
|
|
|
enum ProfileIssue {
|
|
nicknameInvalid,
|
|
signatureInvalid,
|
|
avatarTooLarge,
|
|
avatarUnsupported,
|
|
}
|
|
|
|
class ProfileInputException implements Exception {
|
|
const ProfileInputException(this.issue);
|
|
final ProfileIssue issue;
|
|
}
|
|
|
|
@freezed
|
|
class ProfileState with _$ProfileState {
|
|
const factory ProfileState({
|
|
UserProfile? profile,
|
|
@Default(true) bool loading,
|
|
@Default(false) bool saving,
|
|
String? alert,
|
|
ProfileIssue? issue,
|
|
}) = _ProfileState;
|
|
|
|
factory ProfileState.fromJson(Map<String, dynamic> json) =>
|
|
_$ProfileStateFromJson(json);
|
|
}
|