flutter架 构项目基础

This commit is contained in:
崔宝新
2026-09-04 15:22:20 +08:00
parent 70967229d0
commit 0c5aee59c0
265 changed files with 35484 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import 'package:new_learn/features/exam/question_type.dart';
/// ============================================================
/// 【ExamQuestion】试卷题目接口模型(纯 Dart,无 Isar 依赖)
///
/// 一、为什么不能直接用 Isar 的 Question 模型(web 编译约束):
/// Isar 模型生成的 *.g.dart 含 64 位 schema 哈希常量,
/// dart2js 无法精确表示 → web 编译直接失败(本项目已踩坑)。
/// 业务代码 import Isar 模型 = 把它拉进 web 编译图。
/// 所以试卷功能用本纯 Dart 模型(接口 JSON 解析),
/// WrongQuestionStore 注释的约定:"页面永远不要 import 模型"。
///
/// 二、与 Isar Question 字段对应:
/// questionId/title/answer/analysis 一一对应;
/// options 直接用 `List<String>`(接口 JSON 是数组),
/// Isar 侧存 JSON 字符串只是本地存储的简化写法,语义相同。
/// ============================================================
class ExamQuestion {
const ExamQuestion({
required this.questionId,
required this.title,
required this.options,
required this.answer,
required this.type,
required this.analysis,
});
/// 服务器题号(答案 Map 的 key,续答恢复的关联字段)
final int questionId;
/// 题干(HTML 富文本,RichTextContent 渲染)
final String title;
/// 选项(选择/判断题有值,解答题空列表)
final List<String> options;
/// 正确答案(多选 "A,C" 逗号拼接,判断 "对"/"错",解答为参考答案)
final String answer;
/// 题型(渲染分发的依据)
final QuestionType type;
/// 解析(交卷后查看答案用)
final String analysis;
/// 接口 JSON → 模型(字段缺失兜底空值,防御脏数据)
factory ExamQuestion.fromJson(Map<String, dynamic> json) {
return ExamQuestion(
questionId: json['questionId'] as int,
title: json['title'] as String? ?? '',
options: (json['options'] as List?)?.cast<String>() ?? const [],
answer: json['answer'] as String? ?? '',
type: QuestionType.fromCode(json['type'] as int?),
analysis: json['analysis'] as String? ?? '',
);
}
}