Skip to content

Add Null Safety on Connect/Disconnect Pusher #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YussufEssam89
Copy link

Pull Request: Add Null Safety to Pusher Connect/Disconnect Methods

Summary

This PR enhances the stability of the Pusher Channels Flutter plugin by adding null safety to the connect and disconnect methods. It ensures the pusher instance is safely accessed, preventing potential runtime crashes.

Changes Made

  • Applied optional chaining to pusher in the following methods:
    • connect(result:)
      // Updated from:
      pusher.connect()
      
      // To:
      pusher?.connect()
    • disconnect(result:)
      // Updated from:
      pusher.disconnect()
      
      // To:
      pusher?.disconnect()

Motivation

Previously, calling connect() or disconnect() without initializing the pusher instance could result in a crash. Adding null safety:

  • Prevents unsafe access to pusher
  • Improves plugin reliability
  • Aligns with Swift best practices for handling optionals

Testing

  • Verified that calling connect() and disconnect() before initialization no longer causes crashes.
  • Manually tested plugin behavior under various initialization states to confirm expected outcomes.

Notes

  • No changes were made to existing logic or external plugin behavior.
  • This update is fully backward-compatible.

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