去除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) {
print('请求异常: $e');
print('异常类型: ${e.runtimeType}');
if (mounted) {
setState(() {
_errorMessage = '网络请求失败,请检查网络连接';

View File

@@ -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) {}
}
}

View File

@@ -35,7 +35,7 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() {
_isLoading = true;
});
try {
final history = await HistoryController.getHistory();
setState(() {
@@ -44,7 +44,7 @@ class _HistoryPageState extends State<HistoryPage> {
_isLoading = false;
});
} catch (e) {
print('加载历史记录失败: $e');
// print('加载历史记录失败: $e');
setState(() {
_isLoading = false;
});
@@ -56,14 +56,14 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() {
_searchKeyword = keyword;
});
if (keyword.isEmpty) {
setState(() {
_filteredHistoryList = _historyList;
});
return;
}
_performSearch(keyword);
}
@@ -74,7 +74,7 @@ class _HistoryPageState extends State<HistoryPage> {
_filteredHistoryList = searchResults;
});
} catch (e) {
print('搜索历史记录失败: $e');
// print('搜索历史记录失败: $e');
}
}
@@ -83,24 +83,25 @@ class _HistoryPageState extends State<HistoryPage> {
setState(() {
_selectedSortType = sortType;
});
final sortedList = List<Map<String, dynamic>>.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<HistoryPage> {
'清空历史记录',
'确定要清空所有历史记录吗?此操作不可撤销。',
);
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<void> _deleteHistoryItem(int index, Map<String, dynamic> 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<HistoryPage> {
Future<void> _exportHistory() async {
try {
final exportData = await HistoryController.exportHistory(format: 'json');
if (exportData.isNotEmpty) {
// 这里可以实现文件保存功能
_showSnackBar('导出功能开发中...');
@@ -202,12 +200,12 @@ class _HistoryPageState extends State<HistoryPage> {
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<HistoryPage> {
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<String, int>).entries
.map((entry) => Text('${entry.key}: ${entry.value}'))
.toList(),
@@ -268,8 +267,8 @@ class _HistoryPageState extends State<HistoryPage> {
child: _isLoading
? _buildLoadingWidget()
: _filteredHistoryList.isEmpty
? _buildEmptyWidget()
: _buildHistoryList(),
? _buildEmptyWidget()
: _buildHistoryList(),
),
],
),
@@ -291,24 +290,15 @@ class _HistoryPageState extends State<HistoryPage> {
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<HistoryPage> {
),
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<HistoryPage> {
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<HistoryPage> {
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<HistoryPage> {
),
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<HistoryPage> {
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,
),