This commit is contained in:
Developer
2026-03-31 03:48:14 +08:00
parent 62729615b7
commit 888363785b
26 changed files with 219 additions and 808 deletions

View File

@@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import '../../../constants/app_constants.dart';
import '../../../controllers/sqlite_storage_controller.dart';
import '../../../controllers/shared_preferences_storage_controller.dart';
import '../../../controllers/history_controller.dart';
import '../../../services/network_listener_service.dart';
@@ -47,10 +47,11 @@ class _DistinguishPageState extends State<DistinguishPage> {
Future<void> _loadAnswerRecords() async {
try {
// 获取答题记录列表
List<String> records = await SQLiteStorageController.getStringList(
'poetryAnswerRecords',
defaultValue: [],
);
List<String> records =
await SharedPreferencesStorageController.getStringList(
'poetryAnswerRecords',
defaultValue: [],
);
// 解析记录
_answerRecords = records
@@ -85,27 +86,27 @@ class _DistinguishPageState extends State<DistinguishPage> {
/// 加载统计数据
Future<void> _loadStatistics() async {
try {
_totalQuestions = await SQLiteStorageController.getInt(
_totalQuestions = await SharedPreferencesStorageController.getInt(
'totalQuestions',
defaultValue: 0,
);
_correctAnswers = await SQLiteStorageController.getInt(
_correctAnswers = await SharedPreferencesStorageController.getInt(
'correctAnswers',
defaultValue: 0,
);
_wrongAnswers = await SQLiteStorageController.getInt(
_wrongAnswers = await SharedPreferencesStorageController.getInt(
'wrongAnswers',
defaultValue: 0,
);
int totalTime = await SQLiteStorageController.getInt(
int totalTime = await SharedPreferencesStorageController.getInt(
'totalTime',
defaultValue: 0,
);
_hintCount = await SQLiteStorageController.getInt(
_hintCount = await SharedPreferencesStorageController.getInt(
'hintCount',
defaultValue: 0,
);
_skipCount = await SQLiteStorageController.getInt(
_skipCount = await SharedPreferencesStorageController.getInt(
'skipCount',
defaultValue: 0,
);
@@ -453,7 +454,10 @@ $_poetryLevel
if (confirmed == true) {
try {
await SQLiteStorageController.setStringList('poetryAnswerRecords', []);
await SharedPreferencesStorageController.setStringList(
'poetryAnswerRecords',
[],
);
setState(() {
_answerRecords = [];
});
@@ -810,87 +814,4 @@ $_poetryLevel
}
}
}
// 从答题记录创建笔记
Future<void> _createNoteFromRecords() async {
try {
// 生成答题记录的详细内容
final StringBuffer content = StringBuffer();
content.writeln('## 答题记录汇总');
content.writeln(
'生成时间: ${DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now())}',
);
content.writeln('总记录数: ${_answerRecords.length}');
content.writeln('');
// 统计信息
int correctCount = 0;
int totalCount = _answerRecords.length;
for (final record in _answerRecords) {
if (record['isCorrect'] == true) {
correctCount++;
}
}
content.writeln('### 统计信息');
content.writeln('- 总题数: $totalCount');
content.writeln('- 答对数: $correctCount');
content.writeln('- 答错数: ${totalCount - correctCount}');
content.writeln(
'- 正确率: ${totalCount > 0 ? (correctCount / totalCount * 100).toStringAsFixed(1) : 0}%',
);
content.writeln('');
content.writeln('### 详细记录');
content.writeln('');
for (int i = 0; i < _answerRecords.length; i++) {
final record = _answerRecords[i];
final question = record['question'] ?? '未知题目';
final userAnswer = record['userAnswer'] ?? '未知答案';
final correctAnswer = record['correctAnswer'] ?? '未知答案';
final isCorrect = record['isCorrect'] == true;
final answerTime = record['answerTime'] ?? '未知时间';
final tags = record['tags'] as List<dynamic>? ?? [];
content.writeln('#### ${i + 1}. $question');
content.writeln('- **你的答案**: $userAnswer');
content.writeln('- **正确答案**: $correctAnswer');
content.writeln('- **答题结果**: ${isCorrect ? '✅ 正确' : '❌ 错误'}');
content.writeln('- **答题时间**: ${_formatTime(answerTime)}');
if (tags.isNotEmpty) {
content.writeln('- **标签**: ${tags.join(', ')}');
}
content.writeln('');
}
final noteId = await HistoryController.saveNote(
title: '答题记录_${DateFormat('yyyyMMdd_HHmmss').format(DateTime.now())}',
content: content.toString(),
category: '答题记录',
);
if (noteId != null) {
NetworkListenerService().sendSuccessEvent(
NetworkEventType.noteUpdate,
data: noteId,
);
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('答题记录已保存到笔记')));
}
}
} catch (e) {
debugPrint('创建笔记失败: $e');
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('创建笔记失败: $e')));
}
}
}
}