fix: replace push with pushReplacement in login navigation to prevent…#1057
fix: replace push with pushReplacement in login navigation to prevent…#1057vibhutomer wants to merge 1 commit into
Conversation
… stack leaks Signed-off-by: vibhutomer <vibhutomer25@gmail.com>
WalkthroughThe login page navigation logic is updated to use ChangesLogin Navigation Stack Fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/ui/login_page.dart (1)
372-389: 💤 Low valueConsider using
pushAndRemoveUntilas a more concise alternative.The current pattern of
popUntilfollowed bypushReplacementcorrectly solves the navigation issue. However, you could simplify this to a single navigation call usingpushAndRemoveUntil:Alternative implementation
- Navigator.popUntil(context, ModalRoute.withName('/login-page')); - if (authProvider.isOnboarded || authProvider.isDefault) { globalProvider.setCurrentIndex(1); } else { globalProvider.setCurrentIndex(0); } if (!context.mounted) return; - Navigator.of(context).pushReplacement( + Navigator.of(context).pushAndRemoveUntil( MaterialPageRoute( builder: (context) => Responsive( mobile: DashBoardTabletView(), desktop: DashBoardTabletView(), tablet: DashBoardTabletView(), ), ), + (route) => false, // Remove all routes from the stack );Note: If you need to preserve any routes below the login page (e.g., a splash screen), the current pattern is more appropriate. The suggested
pushAndRemoveUntilwith(route) => falseclears the entire navigation stack.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/ui/login_page.dart` around lines 372 - 389, Replace the two-step navigation (Navigator.popUntil(... ModalRoute.withName('/login-page')) followed by Navigator.of(context).pushReplacement(... Responsive(... DashBoardTabletView()))) with a single Navigator.of(context).pushAndRemoveUntil call that pushes the Responsive/DashBoardTabletView route and removes previous routes (or use a predicate that preserves the splash route if needed); update the code paths that currently reference ModalRoute.withName('/login-page') and pushReplacement so only the new pushAndRemoveUntil is used, keeping the existing globalProvider.setCurrentIndex(...) logic intact before the navigation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/ui/login_page.dart`:
- Around line 372-389: Replace the two-step navigation (Navigator.popUntil(...
ModalRoute.withName('/login-page')) followed by
Navigator.of(context).pushReplacement(... Responsive(...
DashBoardTabletView()))) with a single Navigator.of(context).pushAndRemoveUntil
call that pushes the Responsive/DashBoardTabletView route and removes previous
routes (or use a predicate that preserves the splash route if needed); update
the code paths that currently reference ModalRoute.withName('/login-page') and
pushReplacement so only the new pushAndRemoveUntil is used, keeping the existing
globalProvider.setCurrentIndex(...) logic intact before the navigation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0700fcf4-3177-47fb-b1c4-00dfe4e39977
📒 Files selected for processing (1)
lib/ui/login_page.dart
Description
This PR resolves a critical navigation lifecycle bug where the
LoginPagewas left in the active routing stack after a successful authentication.Previously,
_navigateToHomePage()utilizedNavigator.of(context).push(). This allowed authenticated users to press the hardware back button from the Dashboard and inadvertently return to the Login screen, resulting in a broken User Experience and improper session flow.Changes Made
login_page.dartfrom.push()to.pushReplacement().DashBoardTabletView.Related Issue
Closes #1056
Type of Change
Checklist
Summary by CodeRabbit