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:
hailin 2026-01-14 08:49:52 -08:00
parent f2692a50ed
commit cb3c7623dc
1 changed files with 4 additions and 2 deletions

View File

@ -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