fix(app): 18 处 catch(e) 添加 debugPrint 异常日志
- 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,无需修改
This commit is contained in:
@@ -196,6 +196,7 @@ class SyncEngine {
|
||||
_lastError = '同步中断:网络不可用';
|
||||
return;
|
||||
} catch (e) {
|
||||
debugPrint('SyncEngine.trySync 操作失败: $e');
|
||||
// 操作失败,增加重试计数
|
||||
final retried = operation.copyWith(retryCount: operation.retryCount + 1);
|
||||
|
||||
|
||||
@@ -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: '加载成就列表失败',
|
||||
|
||||
@@ -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<CalendarEvent, CalendarState> {
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('CalendarBloc._onMonthChanged 失败: $e');
|
||||
if (state is CalendarLoaded) {
|
||||
emit((state as CalendarLoaded).copyWith(isLoading: false));
|
||||
}
|
||||
|
||||
@@ -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<HomeEvent, HomeState> {
|
||||
todayWeather: todayWeather,
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('HomeBloc._onLoadData 失败: $e');
|
||||
emit(const HomeLoaded()); // 空状态而非错误,离线友好
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ class MoodBloc extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('MoodBloc._loadStats 失败: $e');
|
||||
_state = _state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: '加载统计数据失败',
|
||||
|
||||
@@ -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<ParentEvent, ParentState> {
|
||||
.toList();
|
||||
emit(ParentChildrenLoaded(children));
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onLoadChildren 失败: $e');
|
||||
emit(const ParentError('加载孩子列表失败'));
|
||||
}
|
||||
}
|
||||
@@ -57,6 +59,7 @@ class ParentBloc extends Bloc<ParentEvent, ParentState> {
|
||||
// 绑定成功后重新加载列表
|
||||
add(const ParentLoadChildren());
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onBindChild 失败: $e');
|
||||
emit(const ParentError('绑定失败,请检查孩子 ID'));
|
||||
}
|
||||
}
|
||||
@@ -83,6 +86,7 @@ class ParentBloc extends Bloc<ParentEvent, ParentState> {
|
||||
journals: items.cast<Map<String, dynamic>>(),
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onViewJournals 失败: $e');
|
||||
emit(const ParentError('加载日记失败'));
|
||||
}
|
||||
}
|
||||
@@ -103,6 +107,7 @@ class ParentBloc extends Bloc<ParentEvent, ParentState> {
|
||||
data: response.data as Map<String, dynamic>,
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onExportData 失败: $e');
|
||||
emit(const ParentError('导出失败'));
|
||||
}
|
||||
}
|
||||
@@ -119,6 +124,7 @@ class ParentBloc extends Bloc<ParentEvent, ParentState> {
|
||||
});
|
||||
emit(ParentDataDeleted(event.childId));
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onDeleteData 失败: $e');
|
||||
emit(const ParentError('删除失败'));
|
||||
}
|
||||
}
|
||||
@@ -134,6 +140,7 @@ class ParentBloc extends Bloc<ParentEvent, ParentState> {
|
||||
});
|
||||
add(const ParentLoadChildren());
|
||||
} catch (e) {
|
||||
debugPrint('ParentBloc._onUnbindChild 失败: $e');
|
||||
emit(const ParentError('解绑失败'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SearchEvent, SearchState> {
|
||||
searchHistory: List.unmodifiable(_searchHistory),
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('SearchBloc._onSearchByMood 失败: $e');
|
||||
emit(const SearchError('搜索失败,请重试'));
|
||||
}
|
||||
}
|
||||
@@ -73,6 +75,7 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
|
||||
searchHistory: List.unmodifiable(_searchHistory),
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('SearchBloc._onSearchByTag 失败: $e');
|
||||
emit(const SearchError('搜索失败,请重试'));
|
||||
}
|
||||
}
|
||||
@@ -113,6 +116,7 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
|
||||
searchHistory: List.unmodifiable(_searchHistory),
|
||||
));
|
||||
} catch (e) {
|
||||
debugPrint('SearchBloc._onSearchByKeyword 失败: $e');
|
||||
emit(const SearchError('搜索失败,请重试'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: '加载模板列表失败',
|
||||
|
||||
Reference in New Issue
Block a user