去除print

This commit is contained in:
Developer
2026-03-30 03:04:36 +08:00
parent 99464d8fe6
commit 71e853587c
3 changed files with 47 additions and 81 deletions

View File

@@ -367,8 +367,6 @@ class _PopularPageState extends State<PopularPage>
} }
} }
} catch (e) { } catch (e) {
print('请求异常: $e');
print('异常类型: ${e.runtimeType}');
if (mounted) { if (mounted) {
setState(() { setState(() {
_errorMessage = '网络请求失败,请检查网络连接'; _errorMessage = '网络请求失败,请检查网络连接';

View File

@@ -81,9 +81,7 @@ class AutoRefreshManager {
} }
void _debugLog(String message) { void _debugLog(String message) {
if (kDebugMode) { if (kDebugMode) {}
print('AutoRefreshManager: $message');
}
} }
} }
@@ -182,9 +180,7 @@ class DebugInfoManager {
} }
void _debugLog(String message) { void _debugLog(String message) {
if (kDebugMode) { if (kDebugMode) {}
print('DebugInfoManager: $message');
}
} }
} }
@@ -330,8 +326,6 @@ class OfflineDataManager {
} }
void _debugLog(String message) { void _debugLog(String message) {
if (kDebugMode) { if (kDebugMode) {}
print('OfflineDataManager: $message');
}
} }
} }

View File

@@ -35,7 +35,7 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() { setState(() {
_isLoading = true; _isLoading = true;
}); });
try { try {
final history = await HistoryController.getHistory(); final history = await HistoryController.getHistory();
setState(() { setState(() {
@@ -44,7 +44,7 @@ class _HistoryPageState extends State<HistoryPage> {
_isLoading = false; _isLoading = false;
}); });
} catch (e) { } catch (e) {
print('加载历史记录失败: $e'); // print('加载历史记录失败: $e');
setState(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
@@ -56,14 +56,14 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() { setState(() {
_searchKeyword = keyword; _searchKeyword = keyword;
}); });
if (keyword.isEmpty) { if (keyword.isEmpty) {
setState(() { setState(() {
_filteredHistoryList = _historyList; _filteredHistoryList = _historyList;
}); });
return; return;
} }
_performSearch(keyword); _performSearch(keyword);
} }
@@ -74,7 +74,7 @@ class _HistoryPageState extends State<HistoryPage> {
_filteredHistoryList = searchResults; _filteredHistoryList = searchResults;
}); });
} catch (e) { } catch (e) {
print('搜索历史记录失败: $e'); // print('搜索历史记录失败: $e');
} }
} }
@@ -83,24 +83,25 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() { setState(() {
_selectedSortType = sortType; _selectedSortType = sortType;
}); });
final sortedList = List<Map<String, dynamic>>.from(_filteredHistoryList); final sortedList = List<Map<String, dynamic>>.from(_filteredHistoryList);
switch (sortType) { switch (sortType) {
case 0: // 时间倒序 case 0: // 时间倒序
sortedList.sort((a, b) => sortedList.sort(
(b['timestamp'] ?? 0).compareTo(a['timestamp'] ?? 0)); (a, b) => (b['timestamp'] ?? 0).compareTo(a['timestamp'] ?? 0),
);
break; break;
case 1: // 时间正序 case 1: // 时间正序
sortedList.sort((a, b) => sortedList.sort(
(a['timestamp'] ?? 0).compareTo(b['timestamp'] ?? 0)); (a, b) => (a['timestamp'] ?? 0).compareTo(b['timestamp'] ?? 0),
);
break; break;
case 2: // 按名称排序 case 2: // 按名称排序
sortedList.sort((a, b) => sortedList.sort((a, b) => (a['name'] ?? '').compareTo(b['name'] ?? ''));
(a['name'] ?? '').compareTo(b['name'] ?? ''));
break; break;
} }
setState(() { setState(() {
_filteredHistoryList = sortedList; _filteredHistoryList = sortedList;
}); });
@@ -112,41 +113,38 @@ class _HistoryPageState extends State<HistoryPage> {
'清空历史记录', '清空历史记录',
'确定要清空所有历史记录吗?此操作不可撤销。', '确定要清空所有历史记录吗?此操作不可撤销。',
); );
if (confirmed == null || !confirmed) return; if (confirmed == null || !confirmed) return;
try { try {
final success = await HistoryController.clearHistory(); final success = await HistoryController.clearHistory();
if (success) { if (success) {
setState(() { setState(() {
_historyList.clear(); _historyList.clear();
_filteredHistoryList.clear(); _filteredHistoryList.clear();
}); });
_showSnackBar('历史记录已清空'); _showSnackBar('历史记录已清空');
} else { } else {
_showSnackBar('清空失败'); _showSnackBar('清空失败');
} }
} catch (e) { } catch (e) {
print('清空历史记录失败: $e'); //('清空历史记录失败: $e');
_showSnackBar('清空失败'); _showSnackBar('清空失败');
} }
} }
// === 删除单条记录 === // === 删除单条记录 ===
Future<void> _deleteHistoryItem(int index, Map<String, dynamic> item) async { Future<void> _deleteHistoryItem(int index, Map<String, dynamic> item) async {
final confirmed = await _showConfirmDialog( final confirmed = await _showConfirmDialog('删除记录', '确定要删除这条历史记录吗?');
'删除记录',
'确定要删除这条历史记录吗?',
);
if (confirmed == null || !confirmed) return; if (confirmed == null || !confirmed) return;
try { try {
final poetryId = item['id'] as int; final poetryId = item['id'] as int;
final success = await HistoryController.removeFromHistory(poetryId); final success = await HistoryController.removeFromHistory(poetryId);
if (success) { if (success) {
// 重新加载历史记录,避免索引不匹配问题 // 重新加载历史记录,避免索引不匹配问题
await _loadHistory(); await _loadHistory();
@@ -164,7 +162,7 @@ class _HistoryPageState extends State<HistoryPage> {
Future<void> _exportHistory() async { Future<void> _exportHistory() async {
try { try {
final exportData = await HistoryController.exportHistory(format: 'json'); final exportData = await HistoryController.exportHistory(format: 'json');
if (exportData.isNotEmpty) { if (exportData.isNotEmpty) {
// 这里可以实现文件保存功能 // 这里可以实现文件保存功能
_showSnackBar('导出功能开发中...'); _showSnackBar('导出功能开发中...');
@@ -202,12 +200,12 @@ class _HistoryPageState extends State<HistoryPage> {
void _showStatsDialog() async { void _showStatsDialog() async {
try { try {
final stats = await HistoryController.getHistoryStats(); final stats = await HistoryController.getHistoryStats();
if (stats.isEmpty) { if (stats.isEmpty) {
_showSnackBar('暂无统计数据'); _showSnackBar('暂无统计数据');
return; return;
} }
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
@@ -223,7 +221,8 @@ class _HistoryPageState extends State<HistoryPage> {
Text('本月: ${stats['thisMonthCount']}'), Text('本月: ${stats['thisMonthCount']}'),
const SizedBox(height: 16), const SizedBox(height: 16),
const Text('热门朝代:'), const Text('热门朝代:'),
if (stats['topDynasties'] != null && stats['topDynasties'] is Map) ...[ if (stats['topDynasties'] != null &&
stats['topDynasties'] is Map) ...[
...(stats['topDynasties'] as Map<String, int>).entries ...(stats['topDynasties'] as Map<String, int>).entries
.map((entry) => Text('${entry.key}: ${entry.value}')) .map((entry) => Text('${entry.key}: ${entry.value}'))
.toList(), .toList(),
@@ -268,8 +267,8 @@ class _HistoryPageState extends State<HistoryPage> {
child: _isLoading child: _isLoading
? _buildLoadingWidget() ? _buildLoadingWidget()
: _filteredHistoryList.isEmpty : _filteredHistoryList.isEmpty
? _buildEmptyWidget() ? _buildEmptyWidget()
: _buildHistoryList(), : _buildHistoryList(),
), ),
], ],
), ),
@@ -291,24 +290,15 @@ class _HistoryPageState extends State<HistoryPage> {
centerTitle: true, centerTitle: true,
actions: [ actions: [
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.delete_sweep, color: AppConstants.primaryColor),
Icons.delete_sweep,
color: AppConstants.primaryColor,
),
onPressed: _historyList.isEmpty ? null : _clearHistory, onPressed: _historyList.isEmpty ? null : _clearHistory,
), ),
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.bar_chart, color: AppConstants.primaryColor),
Icons.bar_chart,
color: AppConstants.primaryColor,
),
onPressed: _showStatsDialog, onPressed: _showStatsDialog,
), ),
IconButton( IconButton(
icon: Icon( icon: Icon(Icons.file_download, color: AppConstants.primaryColor),
Icons.file_download,
color: AppConstants.primaryColor,
),
onPressed: _exportHistory, onPressed: _exportHistory,
), ),
], ],
@@ -340,7 +330,10 @@ class _HistoryPageState extends State<HistoryPage> {
), ),
filled: true, filled: true,
fillColor: Colors.white, 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<HistoryPage> {
SizedBox(height: 16), SizedBox(height: 16),
Text( Text(
'加载历史记录...', '加载历史记录...',
style: TextStyle( style: TextStyle(fontSize: 16, color: Colors.grey[600]!),
fontSize: 16,
color: Colors.grey[600]!,
),
), ),
], ],
), ),
@@ -410,18 +400,11 @@ class _HistoryPageState extends State<HistoryPage> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( Icon(Icons.history, size: 64, color: Colors.grey[400]!),
Icons.history,
size: 64,
color: Colors.grey[400]!,
),
SizedBox(height: 16), SizedBox(height: 16),
Text( Text(
'暂无历史记录', '暂无历史记录',
style: TextStyle( style: TextStyle(fontSize: 16, color: Colors.grey[600]!),
fontSize: 16,
color: Colors.grey[600]!,
),
), ),
SizedBox(height: 16), SizedBox(height: 16),
ElevatedButton( ElevatedButton(
@@ -460,10 +443,7 @@ class _HistoryPageState extends State<HistoryPage> {
), ),
title: Text( title: Text(
item['name'] ?? '未知诗词', item['name'] ?? '未知诗词',
style: const TextStyle( style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
fontSize: 14,
fontWeight: FontWeight.w500,
),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
@@ -472,18 +452,12 @@ class _HistoryPageState extends State<HistoryPage> {
children: [ children: [
Text( Text(
'${item['alias'] ?? '未知朝代'}${item['date'] ?? ''}', '${item['alias'] ?? '未知朝代'}${item['date'] ?? ''}',
style: const TextStyle( style: const TextStyle(fontSize: 12, color: Colors.grey),
fontSize: 12,
color: Colors.grey,
),
), ),
if (item['introduce']?.toString().isNotEmpty == true) if (item['introduce']?.toString().isNotEmpty == true)
Text( Text(
item['introduce']?.toString() ?? '', item['introduce']?.toString() ?? '',
style: TextStyle( style: TextStyle(fontSize: 11, color: Colors.grey[600]!),
fontSize: 11,
color: Colors.grey[600]!,
),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),