Skip to content

Fixed Null check operator used on a null value err#147

Merged
grunch merged 1 commit into
mainfrom
fix/null-check-operator-deep-link
Jul 14, 2025
Merged

Fixed Null check operator used on a null value err#147
grunch merged 1 commit into
mainfrom
fix/null-check-operator-deep-link

Conversation

@grunch

@grunch grunch commented Jul 14, 2025

Copy link
Copy Markdown
Member

Problem: The context was potentially null when being passed to processMostroLink().

Solution: Added proper null checks and context validation in DeepLinkHandler._handleMostroDeepLink():

  • Added mounted check when showing loading dialog
  • Added fallback context retrieval and validation before processing
  • Early return if no valid context is available

Files changed: lib/core/deep_link_handler.dart

Summary by CodeRabbit

  • Bug Fixes

    • Improved router redirect logic to handle custom URI schemes, preventing errors and ensuring unsupported schemes are redirected to the home screen.
    • Enhanced deep link processing to validate context before handling links, increasing app stability and preventing crashes.
  • Improvements

    • Enhanced logging for deep link interception, making logs clearer and easier to trace.
    • Added compatibility for deprecated route handling methods to ensure smoother deep link support across different app versions.

Problem: The context was potentially null when being passed to processMostroLink().

Solution: Added proper null checks and context validation in
DeepLinkHandler._handleMostroDeepLink():
- Added mounted check when showing loading dialog
- Added fallback context retrieval and validation before processing
- Early return if no valid context is available

Files changed: lib/core/deep_link_handler.dart
@coderabbitai

coderabbitai Bot commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes enhance deep link handling and routing logic for custom URI schemes. The router now redirects unsupported or custom schemes to the root path, preventing assertion failures. Deep link context validation is improved for safer processing, and logging is clarified. Compatibility is maintained by overriding a deprecated route method.

Changes

File(s) Change Summary
lib/core/app_routes.dart Router redirect logic updated to handle custom/non-HTTP URI schemes by redirecting them to root.
lib/core/deep_link_handler.dart Improved context validation for deep link handling and safer use of BuildContext.
lib/core/deep_link_interceptor.dart Enhanced logging, added override for deprecated didPushRoute, improved custom scheme interception.

Poem

A hop and a skip through links so deep,
Now custom schemes won’t make us weep.
With context checked and logs anew,
The routes are safe, the path is true.
🐇✨
From root to leaf, the journey’s bright—
Every deep link handled right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5402a0c and 6129d50.

📒 Files selected for processing (3)
  • lib/core/app_routes.dart (1 hunks)
  • lib/core/deep_link_handler.dart (1 hunks)
  • lib/core/deep_link_interceptor.dart (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
lib/**/*.dart

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
**/*.dart

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
🧠 Learnings (1)
lib/core/deep_link_handler.dart (1)
Learnt from: CR
PR: MostroP2P/mobile#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-08T17:55:04.549Z
Learning: Always check `mounted` before using context after async operations
🔇 Additional comments (6)
lib/core/app_routes.dart (1)

34-38: Excellent defensive routing approach.

The redirect logic effectively prevents assertion failures by catching custom schemes before they reach GoRouter's internal validation. The dual condition handles both the specific 'mostro' scheme and provides a safety net for other custom schemes.

lib/core/deep_link_handler.dart (3)

75-75: Good mounted state validation.

Adding the mounted check before showing the loading dialog aligns with the retrieved learning about checking mounted before using context after async operations. This prevents potential crashes if the widget has been disposed.


83-88: Excellent context validation and fallback strategy.

This addresses the core issue mentioned in the PR objectives. The implementation:

  • Provides a fallback to current navigator context if the original is null
  • Validates both existence and mounted state before proceeding
  • Uses early return to prevent execution with invalid context

This robust approach prevents the "Null check operator used on a null value" error effectively.


91-91: Proper use of validated context.

Using processingContext instead of the original context ensures that the deep link processing always operates with a valid, mounted context, preventing runtime errors.

lib/core/deep_link_interceptor.dart (2)

24-24: Improved logging clarity with consistent prefixing.

Adding the "DeepLinkInterceptor:" prefix to log messages improves debugging by clearly identifying the source of each log entry. This helps differentiate interceptor logs from other deep link related logs.

Also applies to: 28-28, 38-38


45-63: Good compatibility handling for deprecated method.

The override of the deprecated didPushRoute method maintains backward compatibility while following the same interception pattern as didPushRouteInformation. The implementation includes:

  • Proper error handling for URI parsing
  • Consistent custom scheme detection logic
  • Appropriate fallback to superclass for non-custom schemes

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@grunch grunch merged commit 80e5e08 into main Jul 14, 2025
2 checks passed
@grunch grunch deleted the fix/null-check-operator-deep-link branch July 14, 2025 23:31
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.

1 participant