重构
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import '../../../config/app_config.dart';
|
||||
|
||||
/// 时间: 2026-03-27
|
||||
/// 功能: 应用数据管理页面
|
||||
@@ -222,39 +221,6 @@ class _AppDataPageState extends State<AppDataPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showRestartDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.refresh, color: AppConstants.primaryColor),
|
||||
const SizedBox(width: 8),
|
||||
const Text('需要重启'),
|
||||
],
|
||||
),
|
||||
content: const Text('数据已清空,需要重启应用才能生效。'),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppConstants.primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('知道了'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
||||
@@ -161,30 +161,6 @@ class _SpGuidePageState extends State<SpGuidePage>
|
||||
}
|
||||
}
|
||||
|
||||
void _skipToEnd() {
|
||||
if (_currentPage == 1) {
|
||||
if (!_agreementAccepted) {
|
||||
_showNeedAcceptAgreementDialog();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_currentPage == 2) {
|
||||
if (!_agreementAccepted) {
|
||||
_showNeedAcceptAgreementDialog();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_pageController.hasClients) {
|
||||
_pageController.animateToPage(
|
||||
_totalPages - 1,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showNeedAcceptAgreementDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../constants/app_constants.dart';
|
||||
import '../../controllers/history_controller.dart';
|
||||
import '../../utils/flutter_compatibility_fix.dart';
|
||||
|
||||
class HistoryPage extends StatefulWidget {
|
||||
const HistoryPage({super.key});
|
||||
@@ -363,7 +362,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
_sortHistory(_sortTypes.indexOf(value!));
|
||||
_sortHistory(_sortTypes.indexOf(value));
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -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')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../constants/app_constants.dart';
|
||||
import '../../../controllers/sqlite_storage_controller.dart';
|
||||
import '../../../controllers/shared_preferences_storage_controller.dart';
|
||||
import 'level-jilu.dart';
|
||||
import 'flow-anim.dart';
|
||||
import 'distinguish.dart';
|
||||
@@ -329,12 +329,21 @@ class _PoetryLevelPageState extends State<PoetryLevelPage>
|
||||
Future<void> _saveAnswerRecord({bool isCorrect = false}) async {
|
||||
try {
|
||||
// 保存统计数据
|
||||
await SQLiteStorageController.setInt('totalQuestions', _totalQuestions);
|
||||
await SQLiteStorageController.setInt('correctAnswers', _correctAnswers);
|
||||
await SQLiteStorageController.setInt('wrongAnswers', _wrongAnswers);
|
||||
await SQLiteStorageController.setInt('totalTime', _totalTime);
|
||||
await SQLiteStorageController.setInt('hintCount', _hintCount);
|
||||
await SQLiteStorageController.setInt('skipCount', _skipCount);
|
||||
await SharedPreferencesStorageController.setInt(
|
||||
'totalQuestions',
|
||||
_totalQuestions,
|
||||
);
|
||||
await SharedPreferencesStorageController.setInt(
|
||||
'correctAnswers',
|
||||
_correctAnswers,
|
||||
);
|
||||
await SharedPreferencesStorageController.setInt(
|
||||
'wrongAnswers',
|
||||
_wrongAnswers,
|
||||
);
|
||||
await SharedPreferencesStorageController.setInt('totalTime', _totalTime);
|
||||
await SharedPreferencesStorageController.setInt('hintCount', _hintCount);
|
||||
await SharedPreferencesStorageController.setInt('skipCount', _skipCount);
|
||||
|
||||
// 保存当前题目的详细记录
|
||||
if (_currentQuestion != null) {
|
||||
@@ -360,16 +369,17 @@ class _PoetryLevelPageState extends State<PoetryLevelPage>
|
||||
};
|
||||
|
||||
// 获取已有的记录列表
|
||||
List<String> records = await SQLiteStorageController.getStringList(
|
||||
'poetryAnswerRecords',
|
||||
defaultValue: [],
|
||||
);
|
||||
List<String> records =
|
||||
await SharedPreferencesStorageController.getStringList(
|
||||
'poetryAnswerRecords',
|
||||
defaultValue: [],
|
||||
);
|
||||
|
||||
// 添加新记录(JSON格式)
|
||||
records.add(jsonEncode(record));
|
||||
|
||||
// 保存更新后的列表
|
||||
await SQLiteStorageController.setStringList(
|
||||
await SharedPreferencesStorageController.setStringList(
|
||||
'poetryAnswerRecords',
|
||||
records,
|
||||
);
|
||||
|
||||
@@ -4,16 +4,13 @@
|
||||
/// 最新变化: 重新设计布局,实现朋友圈风格的个人页面
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../constants/app_constants.dart';
|
||||
import '../../controllers/history_controller.dart';
|
||||
import '../../controllers/sqlite_storage_controller.dart';
|
||||
import '../../utils/flutter_compatibility_fix.dart';
|
||||
import '../../controllers/shared_preferences_storage_controller.dart';
|
||||
import 'history_page.dart';
|
||||
import 'per_card.dart';
|
||||
import 'settings/app_fun.dart';
|
||||
@@ -23,7 +20,6 @@ import 'settings/privacy.dart';
|
||||
import 'settings/learn-us.dart';
|
||||
import 'app-info.dart';
|
||||
import 'level/poetry.dart';
|
||||
import 'guide/sp-guide.dart';
|
||||
import 'guide/permission.dart';
|
||||
import 'guide/app-data.dart';
|
||||
import 'theme/app-diy.dart';
|
||||
@@ -47,10 +43,8 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
double _startY = 0.0;
|
||||
// 历史记录相关
|
||||
List<Map<String, dynamic>> _poetryHistory = [];
|
||||
final String _historyKey = 'poetry_history';
|
||||
|
||||
// 答题统计数据
|
||||
int _totalQuestions = 0;
|
||||
int _correctAnswers = 0;
|
||||
int _todayQuestions = 0;
|
||||
int _weekQuestions = 0;
|
||||
@@ -86,10 +80,6 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleScroll() {
|
||||
// 这个方法现在由手势检测处理
|
||||
}
|
||||
|
||||
void _onPageChanged(int page) {
|
||||
setState(() {
|
||||
_currentPage = page;
|
||||
@@ -107,55 +97,21 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
Future<void> _savePoetryToHistory(Map<String, dynamic> poetryData) async {
|
||||
try {
|
||||
final success = await HistoryController.addToHistory(poetryData);
|
||||
|
||||
if (success) {
|
||||
_showSnackBar('已添加到历史记录');
|
||||
} else {
|
||||
_showSnackBar('该诗词已在历史记录中');
|
||||
}
|
||||
} catch (e) {
|
||||
_showSnackBar('保存失败');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _clearPoetryHistory() async {
|
||||
try {
|
||||
final success = await HistoryController.clearHistory();
|
||||
|
||||
if (success) {
|
||||
setState(() {
|
||||
_poetryHistory.clear();
|
||||
});
|
||||
_showSnackBar('历史记录已清空');
|
||||
} else {
|
||||
_showSnackBar('清空失败');
|
||||
}
|
||||
} catch (e) {
|
||||
_showSnackBar('清空失败');
|
||||
}
|
||||
}
|
||||
|
||||
// === 答题统计相关方法 ===
|
||||
Future<void> _loadPoetryStatistics() async {
|
||||
try {
|
||||
// 加载总体统计
|
||||
_totalQuestions = await SQLiteStorageController.getInt(
|
||||
'totalQuestions',
|
||||
defaultValue: 0,
|
||||
);
|
||||
_correctAnswers = await SQLiteStorageController.getInt(
|
||||
_correctAnswers = await SharedPreferencesStorageController.getInt(
|
||||
'correctAnswers',
|
||||
defaultValue: 0,
|
||||
);
|
||||
|
||||
// 加载答题记录列表来计算今日和本周答题数
|
||||
List<String> records = await SQLiteStorageController.getStringList(
|
||||
'poetryAnswerRecords',
|
||||
defaultValue: [],
|
||||
);
|
||||
List<String> records =
|
||||
await SharedPreferencesStorageController.getStringList(
|
||||
'poetryAnswerRecords',
|
||||
defaultValue: [],
|
||||
);
|
||||
|
||||
final now = DateTime.now();
|
||||
final todayStart = DateTime(now.year, now.month, now.day);
|
||||
@@ -287,158 +243,6 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard(String label, String value, IconData icon) {
|
||||
// === 单个统计卡片:显示统计数据和图标 ===
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: AppConstants.primaryColor, size: 24),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabBar() {
|
||||
// === 页面切换标签栏:显示当前页面指示器 ===
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onVerticalDragStart: (_) {},
|
||||
onVerticalDragUpdate: (_) {},
|
||||
onVerticalDragEnd: (_) {},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppConstants.primaryColor.withValues(alpha: 0.85),
|
||||
AppConstants.primaryColor.withValues(alpha: 0.8),
|
||||
],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
// 页面指示器
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 3,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
// 背景条
|
||||
Container(
|
||||
height: 3,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
// 滑动指示器
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
width: MediaQuery.of(context).size.width / 3 - 40,
|
||||
height: 3,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
margin: EdgeInsets.only(
|
||||
left:
|
||||
(MediaQuery.of(context).size.width / 3 - 40) *
|
||||
_currentPage,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// 页面标签
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildTabLabel(0, '卡片'),
|
||||
_buildTabLabel(1, '设置'),
|
||||
_buildTabLabel(2, '更多'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabLabel(int index, String label) {
|
||||
// === 单个页面标签:可点击切换到对应页面 ===
|
||||
final isSelected = _currentPage == index;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
// 添加 mounted 和 hasClients 检查,避免 dispose 后调用导致黑屏
|
||||
if (mounted && _pageController.hasClients) {
|
||||
_pageController.animateToPage(
|
||||
index,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: isSelected ? Colors.white : Colors.white70,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPage1() {
|
||||
// === 第1页:个人信息卡片展示 ===
|
||||
return SingleChildScrollView(
|
||||
@@ -914,15 +718,6 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
);
|
||||
}
|
||||
|
||||
void _navigateToSpGuidePage() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SpGuidePage(fromSettings: true),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _navigateToPermissionPage() {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -972,129 +767,7 @@ class _ProfilePageState extends State<ProfilePage>
|
||||
);
|
||||
}
|
||||
|
||||
// === 历史记录对话框 ===
|
||||
void _showHistoryDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
// 对话框标题
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'历史记录',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppConstants.primaryColor,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: _poetryHistory.isEmpty
|
||||
? null
|
||||
: () {
|
||||
Navigator.pop(context);
|
||||
_clearPoetryHistory();
|
||||
},
|
||||
child: const Text('清空'),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 历史记录列表
|
||||
Expanded(
|
||||
child: _poetryHistory.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.history,
|
||||
size: 64,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'暂无历史记录',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: _poetryHistory.length,
|
||||
itemBuilder: (context, index) {
|
||||
final poetry = _poetryHistory[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: AppConstants.primaryColor
|
||||
.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppConstants.primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
poetry['name'] ?? '未知诗词',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
'${poetry['alias'] ?? '未知朝代'} • ${poetry['date'] ?? ''}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.favorite_border),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
_showSnackBar('已添加到收藏');
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget? _showMoreOptions() {
|
||||
void _showMoreOptions() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
|
||||
@@ -25,9 +25,7 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
bool _vibrationEnabled = true;
|
||||
bool _darkModeEnabled = false;
|
||||
bool _preloadEnabled = true;
|
||||
bool _notificationEnabled = true;
|
||||
bool _globalTipsEnabled = true; // 添加全局Tips开关状态
|
||||
int _cacheSize = 128;
|
||||
|
||||
static const String _autoRefreshKey = 'auto_refresh_enabled';
|
||||
static const String _debugInfoKey = 'debug_info_enabled';
|
||||
@@ -311,28 +309,6 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCacheItem() {
|
||||
return ListTile(
|
||||
leading: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppConstants.primaryColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(Icons.storage, color: AppConstants.primaryColor, size: 20),
|
||||
),
|
||||
title: const Text(
|
||||
'缓存大小',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
|
||||
),
|
||||
subtitle: Text(
|
||||
'$_cacheSize MB',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||
),
|
||||
trailing: Icon(Icons.chevron_right, color: Colors.grey[400]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionItem(
|
||||
String title,
|
||||
String subtitle,
|
||||
@@ -403,32 +379,6 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
void _showClearCacheDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('清除缓存'),
|
||||
content: const Text('确定要清除所有缓存数据吗?这不会影响您的笔记和收藏。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
setState(() {
|
||||
_cacheSize = 0;
|
||||
});
|
||||
_showSnackBar('缓存已清除');
|
||||
},
|
||||
child: Text('确定', style: TextStyle(color: Colors.red[400])),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showResetDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -450,7 +400,6 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
_vibrationEnabled = true;
|
||||
_globalTipsEnabled = true; // 重置全局Tips开关为开启
|
||||
_darkModeEnabled = false;
|
||||
_notificationEnabled = true;
|
||||
});
|
||||
_showSnackBar('已恢复默认设置');
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user