fix(mining-app): fix Riverpod ref usage in router redirect callback
Use cached auth state from AuthNotifier instead of ref.read() to avoid "Cannot use ref functions after provider changed" exception during rebuild. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f2692a50ed
commit
cb3c7623dc
|
|
@ -31,7 +31,8 @@ class AuthNotifier extends ChangeNotifier {
|
|||
void updateLoginState(bool isLoggedIn) {
|
||||
if (_isLoggedIn != isLoggedIn) {
|
||||
_isLoggedIn = isLoggedIn;
|
||||
notifyListeners();
|
||||
// 使用 Future.microtask 延迟通知,避免在 provider rebuild 期间触发
|
||||
Future.microtask(() => notifyListeners());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +55,8 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
|||
initialLocation: Routes.splash,
|
||||
refreshListenable: authNotifier,
|
||||
redirect: (context, state) {
|
||||
final isLoggedIn = ref.read(isLoggedInProvider);
|
||||
// 使用 authNotifier 中缓存的状态,而不是 ref.read
|
||||
final isLoggedIn = authNotifier.isLoggedIn;
|
||||
final currentPath = state.uri.path;
|
||||
|
||||
// splash 页面不做重定向,让它自己处理初始化逻辑
|
||||
|
|
|
|||
Loading…
Reference in New Issue