From e57c3427a41e011d3ccd905eead7df725ad92554 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 2 Jun 2026 23:21:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(app):=2018=20=E5=A4=84=20catch(e)=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20debugPrint=20=E5=BC=82=E5=B8=B8=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - parent_bloc: 6 处 (LoadChildren/BindChild/ViewJournals/ExportData/DeleteData/UnbindChild) - search_bloc: 3 处 (SearchByMood/SearchByTag/SearchByKeyword) - achievement_bloc: 1 处 (_fetchAchievements) - sticker_bloc: 2 处 (_fetchPacks/fetchStickersInPack) - template_bloc: 1 处 (_fetchTemplates) - mood_bloc: 1 处 (_loadStats) - home_bloc: 1 处 (_onLoadData) - calendar_bloc: 1 处 (_onMonthChanged) - sync_engine: 1 处 (trySync) - weekly_page: 已有 debugPrint,无需修改 --- app/lib/data/services/sync_engine.dart | 1 + app/lib/features/achievement/bloc/achievement_bloc.dart | 2 ++ app/lib/features/calendar/bloc/calendar_bloc.dart | 2 ++ app/lib/features/home/bloc/home_bloc.dart | 2 ++ app/lib/features/mood/bloc/mood_bloc.dart | 1 + app/lib/features/parent/bloc/parent_bloc.dart | 7 +++++++ app/lib/features/search/bloc/search_bloc.dart | 4 ++++ app/lib/features/stickers/bloc/sticker_bloc.dart | 3 +++ app/lib/features/templates/bloc/template_bloc.dart | 2 ++ 9 files changed, 24 insertions(+) diff --git a/app/lib/data/services/sync_engine.dart b/app/lib/data/services/sync_engine.dart index b77bebc..14674c6 100644 --- a/app/lib/data/services/sync_engine.dart +++ b/app/lib/data/services/sync_engine.dart @@ -196,6 +196,7 @@ class SyncEngine { _lastError = '同步中断:网络不可用'; return; } catch (e) { + debugPrint('SyncEngine.trySync 操作失败: $e'); // 操作失败,增加重试计数 final retried = operation.copyWith(retryCount: operation.retryCount + 1); diff --git a/app/lib/features/achievement/bloc/achievement_bloc.dart b/app/lib/features/achievement/bloc/achievement_bloc.dart index 3639915..563fedb 100644 --- a/app/lib/features/achievement/bloc/achievement_bloc.dart +++ b/app/lib/features/achievement/bloc/achievement_bloc.dart @@ -1,5 +1,6 @@ // 成就 BLoC — 通过 API 加载成就列表 +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:nuanji_app/data/remote/api_client.dart'; @@ -98,6 +99,7 @@ class AchievementBloc extends ChangeNotifier { _state = _state.copyWith(isLoading: false, achievements: achievements); } catch (e) { + debugPrint('AchievementBloc._fetchAchievements 失败: $e'); _state = _state.copyWith( isLoading: false, errorMessage: '加载成就列表失败', diff --git a/app/lib/features/calendar/bloc/calendar_bloc.dart b/app/lib/features/calendar/bloc/calendar_bloc.dart index 6bdaa25..def02a5 100644 --- a/app/lib/features/calendar/bloc/calendar_bloc.dart +++ b/app/lib/features/calendar/bloc/calendar_bloc.dart @@ -1,5 +1,6 @@ // 日历 BLoC — 管理日历视图状态,通过 JournalRepository 加载数据 +import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:nuanji_app/data/models/journal_entry.dart'; import 'package:nuanji_app/data/repositories/journal_repository.dart'; @@ -136,6 +137,7 @@ class CalendarBloc extends Bloc { )); } } catch (e) { + debugPrint('CalendarBloc._onMonthChanged 失败: $e'); if (state is CalendarLoaded) { emit((state as CalendarLoaded).copyWith(isLoading: false)); } diff --git a/app/lib/features/home/bloc/home_bloc.dart b/app/lib/features/home/bloc/home_bloc.dart index e6ae4ea..c97ffd4 100644 --- a/app/lib/features/home/bloc/home_bloc.dart +++ b/app/lib/features/home/bloc/home_bloc.dart @@ -1,5 +1,6 @@ // 首页 BLoC — 加载最近日记和心情概览 +import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:nuanji_app/data/models/journal_entry.dart'; import 'package:nuanji_app/data/repositories/journal_repository.dart'; @@ -141,6 +142,7 @@ class HomeBloc extends Bloc { todayWeather: todayWeather, )); } catch (e) { + debugPrint('HomeBloc._onLoadData 失败: $e'); emit(const HomeLoaded()); // 空状态而非错误,离线友好 } } diff --git a/app/lib/features/mood/bloc/mood_bloc.dart b/app/lib/features/mood/bloc/mood_bloc.dart index 71a3234..e92bef9 100644 --- a/app/lib/features/mood/bloc/mood_bloc.dart +++ b/app/lib/features/mood/bloc/mood_bloc.dart @@ -138,6 +138,7 @@ class MoodBloc extends ChangeNotifier { ), ); } catch (e) { + debugPrint('MoodBloc._loadStats 失败: $e'); _state = _state.copyWith( isLoading: false, errorMessage: '加载统计数据失败', diff --git a/app/lib/features/parent/bloc/parent_bloc.dart b/app/lib/features/parent/bloc/parent_bloc.dart index 40361b4..07bbc92 100644 --- a/app/lib/features/parent/bloc/parent_bloc.dart +++ b/app/lib/features/parent/bloc/parent_bloc.dart @@ -3,6 +3,7 @@ // 状态机: ParentInitial → ParentLoading → ParentChildrenLoaded / ParentJournalsLoaded / ParentDataExported / ParentDataDeleted / ParentError // API: /diary/parent/* 端点 +import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../data/remote/api_client.dart'; @@ -40,6 +41,7 @@ class ParentBloc extends Bloc { .toList(); emit(ParentChildrenLoaded(children)); } catch (e) { + debugPrint('ParentBloc._onLoadChildren 失败: $e'); emit(const ParentError('加载孩子列表失败')); } } @@ -57,6 +59,7 @@ class ParentBloc extends Bloc { // 绑定成功后重新加载列表 add(const ParentLoadChildren()); } catch (e) { + debugPrint('ParentBloc._onBindChild 失败: $e'); emit(const ParentError('绑定失败,请检查孩子 ID')); } } @@ -83,6 +86,7 @@ class ParentBloc extends Bloc { journals: items.cast>(), )); } catch (e) { + debugPrint('ParentBloc._onViewJournals 失败: $e'); emit(const ParentError('加载日记失败')); } } @@ -103,6 +107,7 @@ class ParentBloc extends Bloc { data: response.data as Map, )); } catch (e) { + debugPrint('ParentBloc._onExportData 失败: $e'); emit(const ParentError('导出失败')); } } @@ -119,6 +124,7 @@ class ParentBloc extends Bloc { }); emit(ParentDataDeleted(event.childId)); } catch (e) { + debugPrint('ParentBloc._onDeleteData 失败: $e'); emit(const ParentError('删除失败')); } } @@ -134,6 +140,7 @@ class ParentBloc extends Bloc { }); add(const ParentLoadChildren()); } catch (e) { + debugPrint('ParentBloc._onUnbindChild 失败: $e'); emit(const ParentError('解绑失败')); } } diff --git a/app/lib/features/search/bloc/search_bloc.dart b/app/lib/features/search/bloc/search_bloc.dart index d9e806e..ebb4ad9 100644 --- a/app/lib/features/search/bloc/search_bloc.dart +++ b/app/lib/features/search/bloc/search_bloc.dart @@ -3,6 +3,7 @@ // 状态机: SearchInitial → SearchLoading → SearchLoaded/SearchError // 支持关键词搜索、标签筛选、心情筛选、结果分类 tab。 +import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../data/models/journal_entry.dart'; @@ -50,6 +51,7 @@ class SearchBloc extends Bloc { searchHistory: List.unmodifiable(_searchHistory), )); } catch (e) { + debugPrint('SearchBloc._onSearchByMood 失败: $e'); emit(const SearchError('搜索失败,请重试')); } } @@ -73,6 +75,7 @@ class SearchBloc extends Bloc { searchHistory: List.unmodifiable(_searchHistory), )); } catch (e) { + debugPrint('SearchBloc._onSearchByTag 失败: $e'); emit(const SearchError('搜索失败,请重试')); } } @@ -113,6 +116,7 @@ class SearchBloc extends Bloc { searchHistory: List.unmodifiable(_searchHistory), )); } catch (e) { + debugPrint('SearchBloc._onSearchByKeyword 失败: $e'); emit(const SearchError('搜索失败,请重试')); } } diff --git a/app/lib/features/stickers/bloc/sticker_bloc.dart b/app/lib/features/stickers/bloc/sticker_bloc.dart index e0d2fa5..25ed2d4 100644 --- a/app/lib/features/stickers/bloc/sticker_bloc.dart +++ b/app/lib/features/stickers/bloc/sticker_bloc.dart @@ -1,5 +1,6 @@ // 贴纸 BLoC — 通过 API 加载贴纸包和贴纸数据 +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:nuanji_app/data/remote/api_client.dart'; @@ -168,6 +169,7 @@ class StickerBloc extends ChangeNotifier { _state = _state.copyWith(isLoading: false, packs: packs); } catch (e) { + debugPrint('StickerBloc._fetchPacks 失败: $e'); _state = _state.copyWith( isLoading: false, errorMessage: '加载贴纸包失败', @@ -194,6 +196,7 @@ class StickerBloc extends ChangeNotifier { ); }).toList(); } catch (e) { + debugPrint('StickerBloc.fetchStickersInPack 失败: $e'); return []; } } diff --git a/app/lib/features/templates/bloc/template_bloc.dart b/app/lib/features/templates/bloc/template_bloc.dart index 7848566..309c87a 100644 --- a/app/lib/features/templates/bloc/template_bloc.dart +++ b/app/lib/features/templates/bloc/template_bloc.dart @@ -1,5 +1,6 @@ // 模板 BLoC — 通过 API 加载模板列表 +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:nuanji_app/data/remote/api_client.dart'; @@ -125,6 +126,7 @@ class TemplateBloc extends ChangeNotifier { _state = _state.copyWith(isLoading: false, templates: templates); } catch (e) { + debugPrint('TemplateBloc._fetchTemplates 失败: $e'); _state = _state.copyWith( isLoading: false, errorMessage: '加载模板列表失败',