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

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import '../../constants/app_constants.dart';
import '../../utils/responsive_layout.dart';
/// 时间: 2026-03-25
/// 功能: 分类页面
@@ -14,27 +13,67 @@ class CategoryPage extends StatefulWidget {
State<CategoryPage> createState() => _CategoryPageState();
}
class _CategoryPageState extends State<CategoryPage> with SingleTickerProviderStateMixin {
class _CategoryPageState extends State<CategoryPage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final List<String> _tabCategories = ['场景分类', '朝代分类'];
static const sceneData = {
"节日": ["七夕节", "中秋节", "元宵节", "寒食节", "清明节", "端午节", "重阳节", "春节", "节日"],
"季节": ["三月", "二月", "冬天", "夏天", "春天", "春季", "秋天"],
"古籍": ["三国志", "三国演义", "三字经", "中庸", "列子", "史记", "后汉书", "吕氏春秋", "商君书", "围炉夜话", "增广贤文", "墨子", "孙子兵法", "孟子", "小窗幽记", "尚书", "左传", "幼学琼林", "庄子", "战国策", "文心雕龙", "易传", "晋书", "汉书", "淮南子", "礼记", "管子", "红楼梦", "老子", "荀子", "菜根谭", "警世通言", "论语", "资治通鉴", "韩非子", "鬼谷子", "古籍", "格言联璧"],
"古籍": [
"三国志",
"三国演义",
"三字经",
"中庸",
"列子",
"史记",
"后汉书",
"吕氏春秋",
"商君书",
"围炉夜话",
"增广贤文",
"墨子",
"孙子兵法",
"孟子",
"小窗幽记",
"尚书",
"左传",
"幼学琼林",
"庄子",
"战国策",
"文心雕龙",
"易传",
"晋书",
"汉书",
"淮南子",
"礼记",
"管子",
"红楼梦",
"老子",
"荀子",
"菜根谭",
"警世通言",
"论语",
"资治通鉴",
"韩非子",
"鬼谷子",
"古籍",
"格言联璧",
],
"情感": ["伤感", "励志", "友情", "思乡", "思念", "感恩", "爱国", "爱情", "离别"],
"景物": ["庐山", "泰山", "西湖", "长江", "黄河", "边塞", "田园", "山水", "夜景"],
"天文气象": ["写云", "写雨", "写雪", "写风", "星星", "月亮", "流星"],
"动植物": ["写鸟", "柳树", "桃花", "梅花", "竹子", "荷花", "菊花"],
"语言文学": ["对联", "谚语", "一言", "读书", "哲理"],
"其他": ["母亲", "老师", "户外", "礼物", ""]
"其他": ["母亲", "老师", "户外", "礼物", ""],
};
static const dynastyData = {
"主要朝代": ["唐代", "宋代", "元代", "明代", "清代"],
"古代朝代": ["南北朝", "五代", "隋代"],
"近现代": ["近现代", "用户投稿", "管理员测试"],
"其他": ["暂无朝代"]
"其他": ["暂无朝代"],
};
@override
@@ -51,21 +90,20 @@ class _CategoryPageState extends State<CategoryPage> with SingleTickerProviderSt
@override
Widget build(BuildContext context) {
final isDesktop = ResponsiveLayout.isDesktop(context);
final isTablet = ResponsiveLayout.isTablet(context);
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
body: Column(
children: [
// 自定义标题栏
// Tab栏
Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: TabBar(
controller: _tabController,
tabs: _tabCategories.map((category) => Tab(text: category)).toList(),
tabs: _tabCategories
.map((category) => Tab(text: category))
.toList(),
labelColor: AppConstants.primaryColor,
unselectedLabelColor: Colors.grey[600],
indicatorColor: AppConstants.primaryColor,
@@ -88,7 +126,10 @@ class _CategoryPageState extends State<CategoryPage> with SingleTickerProviderSt
);
}
Widget _buildCategoryGrid(Map<String, List<String>> data, String categoryType) {
Widget _buildCategoryGrid(
Map<String, List<String>> data,
String categoryType,
) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: ListView.builder(
@@ -96,7 +137,7 @@ class _CategoryPageState extends State<CategoryPage> with SingleTickerProviderSt
itemBuilder: (context, index) {
final category = data.keys.elementAt(index);
final items = data[category]!;
return Card(
margin: const EdgeInsets.only(bottom: 16.0),
elevation: 2,

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import '../../constants/app_constants.dart';
import '../../utils/responsive_layout.dart';
import '../../utils/http/http_client.dart';
import '../../models/poetry_model.dart';
import '../../controllers/load/locally.dart';

View File

@@ -23,14 +23,6 @@ class _RatePageState extends State<RatePage>
int _debugBarCount = 7;
bool _showDebugPanel = false;
// 活跃度阈值配置
final Map<String, int> _activityThresholds = {
'low': 1, // 1-5
'medium': 6, // 6-20
'high': 21, // 21-100
'veryHigh': 100, // 100+
};
// 模拟活跃度数据 (实际条数)
List<int> _weekData = [];
List<List<int>> _monthData = [];

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import '../constants/app_constants.dart';
import '../utils/responsive_layout.dart';
import '../utils/flutter_compatibility_fix.dart';
import '../widgets/tabbed_nav_app_bar.dart';
import 'active/active_search_page.dart';
import 'active/category_page.dart';
@@ -80,7 +79,6 @@ class _DiscoverPageState extends State<DiscoverPage>
child: TabBarView(
controller: _tabController,
children: _categories.asMap().entries.map((entry) {
final index = entry.key;
final category = entry.value;
// 搜索标签显示 ActiveSearchPage
if (category == '搜索') {

View File

@@ -234,73 +234,4 @@ class _FavoritesPageState extends State<FavoritesPage>
),
);
}
void _showFavoriteDetails(BuildContext context, int index, String category) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('$category详情'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('分类: $category'),
const SizedBox(height: 8),
Text('收藏时间: ${(index + 1) * 2}天前'),
const SizedBox(height: 8),
const Text('这是收藏内容的详细信息。'),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('关闭'),
),
],
),
);
}
void _handleFavoriteAction(String action, int index) {
switch (action) {
case 'share':
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('分享了收藏${index + 1}')));
break;
case 'edit':
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('编辑了收藏${index + 1}')));
break;
case 'delete':
_showDeleteConfirm(index);
break;
}
}
void _showDeleteConfirm(int index) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('确认删除'),
content: Text('确定要删除收藏${index + 1}吗?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('已删除收藏${index + 1}')));
},
child: const Text('删除', style: TextStyle(color: Colors.red)),
),
],
),
);
}
}

View File

@@ -11,7 +11,6 @@ import '../../../constants/app_constants.dart';
import '../../../utils/http/poetry_api.dart';
import '../../../services/network_listener_service.dart';
import '../home/home_components.dart';
import '../home/home_part.dart';
/// 点赞足迹页面
class FootprintPage extends StatefulWidget {

View File

@@ -4,7 +4,6 @@
/// 最新变化: 新建文件
import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../utils/http/poetry_api.dart';

View File

@@ -31,7 +31,6 @@ class _HomePageState extends State<HomePage>
bool _isLoadingLike = false;
String _errorMessage = '';
String _starDisplay = '';
final String _historyKey = 'poetry_history';
List<Map<String, dynamic>> _historyList = [];
int _currentHistoryIndex = -1;
late AnimationController _fadeController;
@@ -41,7 +40,6 @@ class _HomePageState extends State<HomePage>
// 动态加载状态
bool _isLoadingNext = false;
bool _isLoadingPrevious = false;
Map<String, bool> _sectionLoadingStates = {
'title': false,
'content': false,

View File

@@ -524,34 +524,26 @@ class _PoetryCardState extends State<PoetryCard> {
),
),
// 右边:星星和点赞
if (!isLoading &&
(widget.poetryData.star != null ||
widget.poetryData.like != null ||
widget.poetryData.hitsTotal != null))
if (!isLoading)
Row(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.poetryData.star != null) ...[
Text(
PoetryDataUtils.generateStars(widget.poetryData.star),
style: const TextStyle(fontSize: 14),
Text(
PoetryDataUtils.generateStars(widget.poetryData.star),
style: const TextStyle(fontSize: 14),
),
const SizedBox(width: 4),
Text(
PoetryDataUtils.generateLikeText(widget.poetryData.like),
style: const TextStyle(fontSize: 12, color: Colors.grey),
),
const SizedBox(width: 4),
Text(
PoetryDataUtils.generateViewText(
widget.poetryData.hitsTotal,
),
const SizedBox(width: 4),
],
if (widget.poetryData.like != null) ...[
Text(
PoetryDataUtils.generateLikeText(widget.poetryData.like),
style: const TextStyle(fontSize: 12, color: Colors.grey),
),
],
if (widget.poetryData.hitsTotal != null) ...[
Text(
PoetryDataUtils.generateViewText(
widget.poetryData.hitsTotal,
),
style: const TextStyle(fontSize: 12, color: Colors.grey),
),
],
style: const TextStyle(fontSize: 12, color: Colors.grey),
),
],
),
],

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import '../constants/app_constants.dart';
import '../routes/app_routes.dart';
import './home/home_page.dart';
import './discover_page.dart';
import './favorites_page.dart';

View File

@@ -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(

View File

@@ -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,

View File

@@ -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));
}
},
),

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')));
}
}
}
}

View File

@@ -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,
);

View File

@@ -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,

View File

@@ -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('已恢复默认设置');
},