fix(connectivity_plus): prevent crash when NetworkManager is unavailable on Linux #3740
+89
−36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fix: Prevent crash when NetworkManager is unavailable on Linux
Fixes a critical crash in
connectivity_pluson Linux systems where NetworkManager is not installed or not running.Problem
Severity: Critical - Application crashes on startup
Platform: Linux only
Trigger: Calling
Connectivity().checkConnectivity()when NetworkManager is unavailableCrash Details
Applications using
connectivity_plus(including AppFlowy and others) crash on Linux systems without NetworkManager with an uncaught platform error:Why this matters: Not all Linux distributions use NetworkManager (some use systemd-networkd, ConnMan, wicd, etc.), and users may have disabled it. The plugin should work gracefully on all Linux configurations.
Solution
Added defensive error handling with try-catch blocks around NetworkManager DBus calls in two critical locations:
1. checkConnectivity() method
[ConnectivityResult.none]when NetworkManager is unavailable2. _startListenConnectivity() method
[ConnectivityResult.none]to the stream when NetworkManager is unavailableBehavior Changes
ConnectivityResult.noneConnectivityResult.noneTesting
New Tests Added
Added 2 unit tests to verify graceful handling:
NetworkManager unavailable - checkConnectivity
connect()checkConnectivity()returns[ConnectivityResult.none]NetworkManager unavailable - onConnectivityChanged
[ConnectivityResult.none]Test Results
✅ All 11 tests pass (9 existing + 2 new)
✅ No breaking changes
✅ Backward compatible
Impact
✅ Benefits
✅ No Breaking Changes
✅ Edge Cases Covered
Files Changed
lib/src/connectivity_plus_linux.darttest/connectivity_plus_linux_test.dartTotal: 2 files changed, 89 insertions(+), 36 deletions(-)
Rationale
Why return
ConnectivityResult.none?Why catch all exceptions?
nmpackageChecklist