Files
nj/app/lib/data/models/user_settings.dart
iven 5e6c6fdd62 feat(diary): 数据层 + 班级系统 (Phase F1 + B3)
Flutter 数据层 (Phase F1):
- journal_entry.dart: 日记数据模型 (Mood/Weather/tags/version)
- journal_element.dart: 元素模型 (text/image/sticker/handwriting_ref/tape)
- school_class.dart: 班级模型
- user_settings.dart: 用户设置 (主题/画笔/字号)
- isar_database.dart: Isar 初始化
- api_client.dart: Dio + JWT注入 + 离线感知 + 401处理
- journal_repository.dart: 抽象接口 + InMemory实现 (乐观锁)
- sync_engine.dart: WiFi同步 + 操作队列 + 重试(5次) + 快照持久化

Rust 班级系统 (Phase B3):
- class_service.rs: 创建班级(6位码) + 加入班级 + 成员管理
- topic_service.rs: 老师布置主题 + 主题列表
- comment_service.rs: 老师点评 + 评语列表
- class_handler.rs: 5个API端点 + 权限守卫
- topic_handler.rs: 2个API端点
- comment_handler.rs: 2个API端点
- dto.rs: 新增5个DTO (ClassMemberResp/CreateTopicReq/TopicResp/CreateCommentReq/CommentResp)
- 6条新路由注册

验证: cargo check 通过, 433测试全绿, flutter analyze 1 warning
2026-06-01 00:55:51 +08:00

106 lines
3.1 KiB
Dart

// 用户设置数据模型 — 手写不可变类(避免 build_runner 依赖)
/// 主题模式 — 与系统设置同步
enum ThemeMode { light, dark, system }
/// 默认画笔类型(复用 StrokeModel 中的枚举值)
enum DefaultBrushType {
pen('pen'),
pencil('pencil'),
marker('marker');
const DefaultBrushType(this.value);
final String value;
}
/// 用户设置 — 持久化的个人偏好
///
/// 存储用户的主题偏好、默认画笔、字体大小等。
/// 每个用户只有一条设置记录,通过 [userId] 关联。
class UserSettings {
final String id;
final String userId;
final ThemeMode theme;
final DefaultBrushType defaultBrushType;
final String defaultBrushColor;
final double fontSize;
final DateTime createdAt;
final DateTime updatedAt;
const UserSettings({
required this.id,
required this.userId,
this.theme = ThemeMode.system,
this.defaultBrushType = DefaultBrushType.pen,
this.defaultBrushColor = '#2D2420',
this.fontSize = 16.0,
required this.createdAt,
required this.updatedAt,
});
UserSettings copyWith({
String? id,
String? userId,
ThemeMode? theme,
DefaultBrushType? defaultBrushType,
String? defaultBrushColor,
double? fontSize,
DateTime? createdAt,
DateTime? updatedAt,
}) =>
UserSettings(
id: id ?? this.id,
userId: userId ?? this.userId,
theme: theme ?? this.theme,
defaultBrushType: defaultBrushType ?? this.defaultBrushType,
defaultBrushColor: defaultBrushColor ?? this.defaultBrushColor,
fontSize: fontSize ?? this.fontSize,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
Map<String, dynamic> toJson() => {
'id': id,
'user_id': userId,
'theme': theme.name,
'default_brush_type': defaultBrushType.value,
'default_brush_color': defaultBrushColor,
'font_size': fontSize,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
};
factory UserSettings.fromJson(Map<String, dynamic> json) => UserSettings(
id: json['id'] as String,
userId: json['user_id'] as String,
theme: ThemeMode.values.firstWhere(
(t) => t.name == json['theme'],
orElse: () => ThemeMode.system,
),
defaultBrushType: DefaultBrushType.values.firstWhere(
(b) => b.value == json['default_brush_type'],
orElse: () => DefaultBrushType.pen,
),
defaultBrushColor:
(json['default_brush_color'] as String?) ?? '#2D2420',
fontSize: (json['font_size'] as num?)?.toDouble() ?? 16.0,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
);
/// 创建默认设置的工厂方法
factory UserSettings.create({
required String userId,
ThemeMode theme = ThemeMode.system,
}) {
final now = DateTime.now();
return UserSettings(
id: userId,
userId: userId,
theme: theme,
createdAt: now,
updatedAt: now,
);
}
}