补充
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/// 创建时间: 2026-05-21
|
||||
/// 更新时间: 2026-06-07
|
||||
/// 作用: 管理账户洞察通知的状态(加载/已读/忽略/删除/刷新)
|
||||
/// 上次更新: refresh()增加authProvider初始化状态检查,防止未初始化崩溃
|
||||
/// 上次更新: 修复build()中_loadFromCache访问state导致循环依赖,改为同步加载缓存作为初始状态
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -48,15 +48,12 @@ class AccountInsightsState {
|
||||
class AccountInsightsNotifier extends Notifier<AccountInsightsState> {
|
||||
@override
|
||||
AccountInsightsState build() {
|
||||
_loadFromCache();
|
||||
return const AccountInsightsState();
|
||||
}
|
||||
|
||||
Future<void> _loadFromCache() async {
|
||||
// 同步加载缓存,直接作为初始状态返回,避免在 build 中访问 state 导致循环依赖
|
||||
final cached = AccountInsightsService.loadInsights();
|
||||
if (cached.isNotEmpty) {
|
||||
state = state.copyWith(insights: _mergeWithExpired(cached));
|
||||
return AccountInsightsState(insights: _mergeWithExpired(cached));
|
||||
}
|
||||
return const AccountInsightsState();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
|
||||
Reference in New Issue
Block a user