From 71e853587ca8ed24853705b4446582e8f09a9164 Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 30 Mar 2026 03:04:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/views/active/popular_page.dart | 2 - lib/views/home/home-load.dart | 12 +-- lib/views/profile/history_page.dart | 114 +++++++++++----------------- 3 files changed, 47 insertions(+), 81 deletions(-) diff --git a/lib/views/active/popular_page.dart b/lib/views/active/popular_page.dart index 69e6775..487d092 100644 --- a/lib/views/active/popular_page.dart +++ b/lib/views/active/popular_page.dart @@ -367,8 +367,6 @@ class _PopularPageState extends State } } } catch (e) { - print('请求异常: $e'); - print('异常类型: ${e.runtimeType}'); if (mounted) { setState(() { _errorMessage = '网络请求失败,请检查网络连接'; diff --git a/lib/views/home/home-load.dart b/lib/views/home/home-load.dart index 07cf925..dcd3de8 100644 --- a/lib/views/home/home-load.dart +++ b/lib/views/home/home-load.dart @@ -81,9 +81,7 @@ class AutoRefreshManager { } void _debugLog(String message) { - if (kDebugMode) { - print('AutoRefreshManager: $message'); - } + if (kDebugMode) {} } } @@ -182,9 +180,7 @@ class DebugInfoManager { } void _debugLog(String message) { - if (kDebugMode) { - print('DebugInfoManager: $message'); - } + if (kDebugMode) {} } } @@ -330,8 +326,6 @@ class OfflineDataManager { } void _debugLog(String message) { - if (kDebugMode) { - print('OfflineDataManager: $message'); - } + if (kDebugMode) {} } } diff --git a/lib/views/profile/history_page.dart b/lib/views/profile/history_page.dart index 8c16f13..af4ed7b 100644 --- a/lib/views/profile/history_page.dart +++ b/lib/views/profile/history_page.dart @@ -35,7 +35,7 @@ class _HistoryPageState extends State { setState(() { _isLoading = true; }); - + try { final history = await HistoryController.getHistory(); setState(() { @@ -44,7 +44,7 @@ class _HistoryPageState extends State { _isLoading = false; }); } catch (e) { - print('加载历史记录失败: $e'); + // print('加载历史记录失败: $e'); setState(() { _isLoading = false; }); @@ -56,14 +56,14 @@ class _HistoryPageState extends State { setState(() { _searchKeyword = keyword; }); - + if (keyword.isEmpty) { setState(() { _filteredHistoryList = _historyList; }); return; } - + _performSearch(keyword); } @@ -74,7 +74,7 @@ class _HistoryPageState extends State { _filteredHistoryList = searchResults; }); } catch (e) { - print('搜索历史记录失败: $e'); + // print('搜索历史记录失败: $e'); } } @@ -83,24 +83,25 @@ class _HistoryPageState extends State { setState(() { _selectedSortType = sortType; }); - + final sortedList = List>.from(_filteredHistoryList); - + switch (sortType) { case 0: // 时间倒序 - sortedList.sort((a, b) => - (b['timestamp'] ?? 0).compareTo(a['timestamp'] ?? 0)); + sortedList.sort( + (a, b) => (b['timestamp'] ?? 0).compareTo(a['timestamp'] ?? 0), + ); break; case 1: // 时间正序 - sortedList.sort((a, b) => - (a['timestamp'] ?? 0).compareTo(b['timestamp'] ?? 0)); + sortedList.sort( + (a, b) => (a['timestamp'] ?? 0).compareTo(b['timestamp'] ?? 0), + ); break; case 2: // 按名称排序 - sortedList.sort((a, b) => - (a['name'] ?? '').compareTo(b['name'] ?? '')); + sortedList.sort((a, b) => (a['name'] ?? '').compareTo(b['name'] ?? '')); break; } - + setState(() { _filteredHistoryList = sortedList; }); @@ -112,41 +113,38 @@ class _HistoryPageState extends State { '清空历史记录', '确定要清空所有历史记录吗?此操作不可撤销。', ); - + if (confirmed == null || !confirmed) return; - + try { final success = await HistoryController.clearHistory(); - + if (success) { setState(() { _historyList.clear(); _filteredHistoryList.clear(); }); - + _showSnackBar('历史记录已清空'); } else { _showSnackBar('清空失败'); } } catch (e) { - print('清空历史记录失败: $e'); + //('清空历史记录失败: $e'); _showSnackBar('清空失败'); } } // === 删除单条记录 === Future _deleteHistoryItem(int index, Map item) async { - final confirmed = await _showConfirmDialog( - '删除记录', - '确定要删除这条历史记录吗?', - ); - + final confirmed = await _showConfirmDialog('删除记录', '确定要删除这条历史记录吗?'); + if (confirmed == null || !confirmed) return; - + try { final poetryId = item['id'] as int; final success = await HistoryController.removeFromHistory(poetryId); - + if (success) { // 重新加载历史记录,避免索引不匹配问题 await _loadHistory(); @@ -164,7 +162,7 @@ class _HistoryPageState extends State { Future _exportHistory() async { try { final exportData = await HistoryController.exportHistory(format: 'json'); - + if (exportData.isNotEmpty) { // 这里可以实现文件保存功能 _showSnackBar('导出功能开发中...'); @@ -202,12 +200,12 @@ class _HistoryPageState extends State { void _showStatsDialog() async { try { final stats = await HistoryController.getHistoryStats(); - + if (stats.isEmpty) { _showSnackBar('暂无统计数据'); return; } - + showDialog( context: context, builder: (context) => AlertDialog( @@ -223,7 +221,8 @@ class _HistoryPageState extends State { Text('本月: ${stats['thisMonthCount']}'), const SizedBox(height: 16), const Text('热门朝代:'), - if (stats['topDynasties'] != null && stats['topDynasties'] is Map) ...[ + if (stats['topDynasties'] != null && + stats['topDynasties'] is Map) ...[ ...(stats['topDynasties'] as Map).entries .map((entry) => Text('${entry.key}: ${entry.value}')) .toList(), @@ -268,8 +267,8 @@ class _HistoryPageState extends State { child: _isLoading ? _buildLoadingWidget() : _filteredHistoryList.isEmpty - ? _buildEmptyWidget() - : _buildHistoryList(), + ? _buildEmptyWidget() + : _buildHistoryList(), ), ], ), @@ -291,24 +290,15 @@ class _HistoryPageState extends State { centerTitle: true, actions: [ IconButton( - icon: Icon( - Icons.delete_sweep, - color: AppConstants.primaryColor, - ), + icon: Icon(Icons.delete_sweep, color: AppConstants.primaryColor), onPressed: _historyList.isEmpty ? null : _clearHistory, ), IconButton( - icon: Icon( - Icons.bar_chart, - color: AppConstants.primaryColor, - ), + icon: Icon(Icons.bar_chart, color: AppConstants.primaryColor), onPressed: _showStatsDialog, ), IconButton( - icon: Icon( - Icons.file_download, - color: AppConstants.primaryColor, - ), + icon: Icon(Icons.file_download, color: AppConstants.primaryColor), onPressed: _exportHistory, ), ], @@ -340,7 +330,10 @@ class _HistoryPageState extends State { ), filled: true, fillColor: Colors.white, - contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 12, + ), ), ), ); @@ -394,10 +387,7 @@ class _HistoryPageState extends State { SizedBox(height: 16), Text( '加载历史记录...', - style: TextStyle( - fontSize: 16, - color: Colors.grey[600]!, - ), + style: TextStyle(fontSize: 16, color: Colors.grey[600]!), ), ], ), @@ -410,18 +400,11 @@ class _HistoryPageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( - Icons.history, - size: 64, - color: Colors.grey[400]!, - ), + Icon(Icons.history, size: 64, color: Colors.grey[400]!), SizedBox(height: 16), Text( '暂无历史记录', - style: TextStyle( - fontSize: 16, - color: Colors.grey[600]!, - ), + style: TextStyle(fontSize: 16, color: Colors.grey[600]!), ), SizedBox(height: 16), ElevatedButton( @@ -460,10 +443,7 @@ class _HistoryPageState extends State { ), title: Text( item['name'] ?? '未知诗词', - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - ), + style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500), maxLines: 2, overflow: TextOverflow.ellipsis, ), @@ -472,18 +452,12 @@ class _HistoryPageState extends State { children: [ Text( '${item['alias'] ?? '未知朝代'} • ${item['date'] ?? ''}', - style: const TextStyle( - fontSize: 12, - color: Colors.grey, - ), + style: const TextStyle(fontSize: 12, color: Colors.grey), ), if (item['introduce']?.toString().isNotEmpty == true) Text( item['introduce']?.toString() ?? '', - style: TextStyle( - fontSize: 11, - color: Colors.grey[600]!, - ), + style: TextStyle(fontSize: 11, color: Colors.grey[600]!), maxLines: 2, overflow: TextOverflow.ellipsis, ),