Skip to content

Fix redundant Provider.of call causing unnecessary rebuilds in AuthScreen#187

Open
AnasNasr-afk wants to merge 2 commits intoAOSSIE-Org:mainfrom
AnasNasr-afk:fix/authscreen-provider-rebuild
Open

Fix redundant Provider.of call causing unnecessary rebuilds in AuthScreen#187
AnasNasr-afk wants to merge 2 commits intoAOSSIE-Org:mainfrom
AnasNasr-afk:fix/authscreen-provider-rebuild

Conversation

@AnasNasr-afk
Copy link
Copy Markdown

@AnasNasr-afk AnasNasr-afk commented Mar 8, 2026

Closes #186

Problem

AuthScreen.build() contained a discarded Provider.of<AuthProvider> call:

Provider.of(context, listen: true).authNavigationStatus;

The returned value was never used, but the call still subscribed the widget to
AuthProvider updates. This caused unnecessary widget rebuilds whenever the
provider changed, creating avoidable UI work.

Additionally:

  • An unused hasNavigated flag was present.
  • Navigation logic was embedded directly in lifecycle code, making it harder to read and maintain.

Changes

  • Removed the unused Provider.of<AuthProvider> call.
  • Removed the unused hasNavigated variable.
  • Extracted navigation logic into a dedicated _handleNavigation() method.
  • Added a mounted safety check before executing navigation from async callbacks.

Result

  • Prevents unnecessary widget rebuilds.
  • Improves readability and separation of concerns in AuthScreen.
  • Makes navigation logic clearer and safer.

Files Changed

lib/presentation/auth/auth_screen.dart

Summary by CodeRabbit

  • Bug Fixes
    • Improved authentication navigation stability with added safety checks to prevent potential crashes during auth flow transitions.
    • Enhanced error handling to display user-facing error messages when authentication navigation issues occur.
  • Chores
    • Added IDE project and workspace configuration files to streamline developer environment setup.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f3b0fd39-34e6-4167-95c9-d7a5a47b7644

📥 Commits

Reviewing files that changed from the base of the PR and between f51f8f0 and 8e81af6.

📒 Files selected for processing (1)
  • patient/lib/presentation/auth/auth_screen.dart

📝 Walkthrough

Walkthrough

Adds IntelliJ IDEA project/workspace configuration files and refactors auth navigation in auth_screen.dart to a status-driven flow with mounted safety checks and removal of a redundant Provider call.

Changes

Cohort / File(s) Summary
IDE Configuration Files
.idea/NeuroTrack.iml, .idea/misc.xml, .idea/modules.xml, .idea/other.xml, .idea/vcs.xml, .idea/workspace.xml
New IntelliJ project and workspace metadata: module config, JDK and output settings, module listing, VCS mapping, extensive persisted device profiles, and per-user workspace preferences.
Auth screen navigation
patient/lib/presentation/auth/auth_screen.dart
Replaced lifecycle-driven navigation with a centralized _handleNavigation(AuthNavigationStatus) invoked via post-frame callback when status changes; added mounted checks and removed a redundant Provider.of that caused unnecessary rebuilds.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant AuthProvider
participant AuthScreen
participant WidgetsBinding as FrameScheduler
participant Navigator
AuthProvider->>AuthScreen: update authNavigationStatus
AuthScreen->>FrameScheduler: schedule post-frame callback
FrameScheduler->>AuthScreen: invoke callback
AuthScreen->>Navigator: pushReplacement(target screen)
Navigator->>AuthScreen: replace route

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • mdmohsin7

Poem

🐇 I hopped through configs, tidy and neat,
Removed a redundant, noisy beat.
Status now guides where users roam,
Post-frame hops bring them safely home.
A carrot-coded cheer — swift and sweet!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes substantial out-of-scope changes: IDE configuration files (.idea/*) totaling 1,461 lines are added despite the linked issue only targeting auth_screen.dart. Remove all IDE configuration files (.idea/NeuroTrack.iml, .idea/misc.xml, .idea/modules.xml, .idea/other.xml, .idea/vcs.xml, .idea/workspace.xml) and focus the PR solely on auth_screen.dart fixes.
Linked Issues check ❓ Inconclusive The PR partially addresses linked issue #186. It removes redundant Provider.of subscriptions and adds mounted checks, but significantly expands the navigation approach beyond the issue's scope. Verify that the new status-driven navigation with context.watch and post-frame callbacks maintains the original behavior and fulfills the goal of preventing unnecessary rebuilds while keeping navigation reactive.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: removing a redundant Provider.of call in AuthScreen to prevent unnecessary rebuilds, matching the primary change in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
.idea/vcs.xml (1)

1-6: IDE configuration files should not be committed to version control.

The .idea/ directory contains IDE-specific settings that vary per developer. Add .idea/ to .gitignore to prevent these files from being tracked. This applies to all .idea/* files in this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.idea/vcs.xml around lines 1 - 6, Remove IDE-specific files from the
repository and stop tracking them by adding ".idea/" to .gitignore and removing
the current tracked .idea files from Git; specifically, add the pattern ".idea/"
to the .gitignore file, then run git rm --cached on the tracked .idea files
(e.g., the VcsDirectoryMappings entry shown in .idea/vcs.xml) and commit that
change so the IDE files are no longer tracked going forward.
.idea/other.xml (1)

1-1319: Remove developer-specific device configuration from version control.

This file contains 1300+ lines of device selection preferences that are specific to your local IDE setup. It adds unnecessary repository bloat and will cause merge conflicts when multiple developers work on the project.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.idea/other.xml around lines 1 - 1319, The .idea/other.xml contains
developer-specific deviceSelectionList entries (PersistentDeviceSelectionData /
component name="direct_access_persist.xml") that should not be versioned; remove
this file from the repo, add .idea/other.xml (or the specific .idea pattern that
contains direct_access_persist.xml) to .gitignore, run git rm --cached
.idea/other.xml and commit the removal, and update the PR to only include a
brief README or contributing note explaining how devs can export/import their
local device profiles (or use IDE's Settings Repository) instead of committing
these PersistentDeviceSelectionData entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.idea/workspace.xml:
- Around line 29-42: The workspace file .idea/workspace.xml contains a local
absolute path in the key "last_opened_file_path" (value
"/Users/anasnasr/StudioProjects/NeuroTrack") and must not be committed; remove
that entry or revert the file to a clean, non-personal version, add
.idea/workspace.xml to .gitignore (or update your repo-level ignore rules) so
workspace files are excluded going forward, and amend the commit (or create a
new one) to remove the sensitive path from history (use an interactive amend or
remove+commit and, if necessary, rewrite history with git rebase or
filter-branch/BFG) so the username/local directory is not present in the repo.

In `@patient/lib/presentation/auth/auth_screen.dart`:
- Around line 126-133: The post-frame callback captures the snapshot `status`
leading to stale navigation when AuthProvider updates rapidly; change the
callback to re-read the current status from AuthProvider inside the callback
(e.g., via context.read<AuthProvider>().authNavigationStatus) and then call
_handleNavigation with that fresh value, while keeping the mounted check and the
conditional that prevents scheduling for unknown status; update the
WidgetsBinding.instance.addPostFrameCallback block accordingly so it never uses
the captured `status` variable.

---

Nitpick comments:
In @.idea/other.xml:
- Around line 1-1319: The .idea/other.xml contains developer-specific
deviceSelectionList entries (PersistentDeviceSelectionData / component
name="direct_access_persist.xml") that should not be versioned; remove this file
from the repo, add .idea/other.xml (or the specific .idea pattern that contains
direct_access_persist.xml) to .gitignore, run git rm --cached .idea/other.xml
and commit the removal, and update the PR to only include a brief README or
contributing note explaining how devs can export/import their local device
profiles (or use IDE's Settings Repository) instead of committing these
PersistentDeviceSelectionData entries.

In @.idea/vcs.xml:
- Around line 1-6: Remove IDE-specific files from the repository and stop
tracking them by adding ".idea/" to .gitignore and removing the current tracked
.idea files from Git; specifically, add the pattern ".idea/" to the .gitignore
file, then run git rm --cached on the tracked .idea files (e.g., the
VcsDirectoryMappings entry shown in .idea/vcs.xml) and commit that change so the
IDE files are no longer tracked going forward.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d9fbc17-d119-41ff-ba0f-97a839a71727

📥 Commits

Reviewing files that changed from the base of the PR and between f474c4c and f51f8f0.

⛔ Files ignored due to path filters (1)
  • patient/pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .idea/NeuroTrack.iml
  • .idea/misc.xml
  • .idea/modules.xml
  • .idea/other.xml
  • .idea/vcs.xml
  • .idea/workspace.xml
  • patient/lib/presentation/auth/auth_screen.dart

Comment on lines +29 to +42
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"RunOnceActivity.readMode.enableVisualFormatting": "true",
"cf.first.check.clang-format": "false",
"cidr.known.project.marker": "true",
"dart.analysis.tool.window.visible": "false",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "/Users/anasnasr/StudioProjects/NeuroTrack",
"show.migrate.to.gradle.popup": "false"
}
}]]></component>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Workspace file contains local machine paths and should not be committed.

Line 39 exposes the local path /Users/anasnasr/StudioProjects/NeuroTrack, which reveals your username and local directory structure. Workspace files are inherently per-developer and should be excluded via .gitignore.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.idea/workspace.xml around lines 29 - 42, The workspace file
.idea/workspace.xml contains a local absolute path in the key
"last_opened_file_path" (value "/Users/anasnasr/StudioProjects/NeuroTrack") and
must not be committed; remove that entry or revert the file to a clean,
non-personal version, add .idea/workspace.xml to .gitignore (or update your
repo-level ignore rules) so workspace files are excluded going forward, and
amend the commit (or create a new one) to remove the sensitive path from history
(use an interactive amend or remove+commit and, if necessary, rewrite history
with git rebase or filter-branch/BFG) so the username/local directory is not
present in the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Discarded Provider.of call in AuthScreen causes unnecessary widget rebuilds

1 participant