rx_connectivity_checker 2.0.0
rx_connectivity_checker: ^2.0.0 copied to clipboard
A robust, reactive Dart/Flutter package for monitoring network connectivity.
Changelog #
All notable changes to this project will be documented in this file.
2.0.0 #
Breaking changes #
- Requires Flutter 3.44 or later. Needed for Android Gradle Plugin 9 with built-in Kotlin (see "Changed") and for Swift Package Manager.
connectivityStreamemits only when the status changes, except forcheckConnectivity()results, which are always emitted. Repeated identical results (e.g.onlinefrom every periodic check) are no longer re-emitted. A new listener immediately receives the last known status instead of always starting fromunknown.checkConnectivity()always runs a fresh check. It is no longer throttled and no longer returns the result of an older in-flight check; it also restarts the periodic timer.slownow means a slow successful response, and a timeout is alwaysoffline. Previously, withcheckSlowConnectionenabled, a request that never got a response was reported asslow(except on Windows). Now a 2xx response slower thanslowConnectionThresholdisslow, and no response withintimeoutisofflineon every platform.- A native "network lost" event emits
offlineimmediately, without an HTTP probe. - Periodic checks pause while the app is hidden (backgrounded or minimised) and resume with an immediate check when it becomes visible again.
ConnectivityCheckerConstants.defaultThrottleTimeis deprecated and unused.
Added #
- Swift Package Manager support — the iOS and macOS implementations now ship a
Package.swift, removing the "does not have Swift Package Manager support" warning. CocoaPods remains fully supported. recheckDelays— new optionalConnectivityCheckerparameter controlling the follow-up checks after a native network change (default: 250 ms, 500 ms, 1 s, 2 s, 4 s).offlineCheckFrequency— interval between periodic checks while not online (default: 5 s);checkFrequencynow applies while online.slowConnectionThreshold— response time above which a successful check isslowwhencheckSlowConnectionis enabled (default: 3 s).
Fixed #
- Reconnection not detected when the platform does not report it — after a "lost" event, recovery depended entirely on a native "available" event, which the iOS Simulator often never sends. Periodic checks now run every
offlineCheckFrequencywhile not online. slowreported on networks without internet access — e.g. an Android emulator whose Wi-Fi has no upstream: requests hang until the timeout, which was mapped toslow. A timeout is nowoffline.- Manual checks could leave no trace on the stream — a
checkConnectivity()result equal to the current status was not emitted. It now always is. - Stream stopped working after every listener cancelled —
connectivityStreamusedshareReplay, which closes for good once the last listener cancels, so a screen subscribing later received one stale value and then nothing. Monitoring now starts with the first listener, stops with the last and restarts when a new listener subscribes. - Slow reaction to native network changes — every native event waited for an HTTP probe before anything was emitted (on "lost", up to
timeout). "Lost" is now reported instantly; "available" triggers an immediate probe with quick follow-up re-checks untilonline, since a link that has just come up often cannot carry traffic yet. A native event arriving while a check is in flight is no longer dropped, and results made stale by a newer event are discarded. - Android reported per-network events — the plugin listened to every network, so turning off Wi-Fi reported "lost" even when mobile data took over, and signal-strength changes triggered constant probes. It now follows the system default network only, reports "lost" at startup when there is no network, and debounces loss by 300 ms to absorb network handovers.
- Linux reported "lost" for anything short of full connectivity — including NetworkManager's
UNKNOWNconnectivity (checking disabled, the default on some distributions), captive portals, limited and transitional states, and machines without a reachable NetworkManager. It now reports "lost" only when there is no network at all (NM_CONNECTIVITY_NONE,NM_STATE_ASLEEP,NM_STATE_DISCONNECTED) and lets the Dart side verify access over HTTP in every other case. - Linux lost updates after a quick unsubscribe/subscribe — e.g. navigating from one listening screen to another: cleanup of the old D-Bus session could close the new session's connection. Each session now owns its connection.
- Native builds failing with
Undefined name 'LinuxRxConnectivityChecker'— the Linux plugin declaration usedfileNameinstead ofdartFileName, so the generated plugin registrant imported the public library, which no longer exports the Linux implementation. The registrant now importssrc/linux_rx_connectivity_checker.dartdirectly. - Privacy manifest is now bundled —
PrivacyInfo.xcprivacywas present but never included by the podspecs. It is now packaged viaresource_bundles(CocoaPods) andresources(SwiftPM) on both iOS and macOS.
Changed #
- Android: migrated to built-in Kotlin — the plugin no longer applies the Kotlin Gradle Plugin itself, which Android Gradle Plugin 9 rejects when built-in Kotlin is enabled and Flutter flags with "plugins that apply KGP" warnings. Flutter 3.44+ applies Kotlin when the app does not use built-in Kotlin. The Android build script is now
android/build.gradle.kts. - Example app — upgraded to Gradle 9.3.1, Android Gradle Plugin 9.1.0 and Kotlin 2.4.0, the versions of the Flutter 3.47 templates (removes the "support for your project's Gradle version will soon be dropped" warning).
- Native source layout — Swift sources and privacy manifests moved from
ios|macos/Classesandios|macos/Resourcestoios|macos/rx_connectivity_checker/Sources/rx_connectivity_checker/, as required by SwiftPM. - macOS minimum deployment target raised from 10.14 to 10.15 in the podspec to match Flutter's own minimum and the SwiftPM manifest.
- Podspec versions are now kept in sync with the package version (were
1.0.1).
1.0.0 #
Added #
- Federated Architecture — transitioned to a federated plugin model, adding native support for macOS, Windows, and Linux.
- Modern Web Support — migrated web implementation to use
package:webanddart:js_interopfor WASM compatibility. - Multi-Trigger System — added support for platform-native change events, periodic heartbeats, and manual on-demand checks.
- Platform Behaviour Documentation — added a platform-behaviour table to the README and
ConnectivityCheckerclass doc clearly stating thatcheckSlowConnectionis silently ignored on Windows (timeouts always map toofflineon that platform). - Dependency Injection —
IHttpClientis now a documented public interface, enabling full unit-test coverage without real network access. - MIT License — updated the project license from Apache 2.0 to MIT.
Changed #
- Internal Strategy Pattern — introduced
ReachabilityValidatorabstraction with conditional imports to improve build-time platform resolution and testability. defaultCheckUrlis now immutable — changed from a mutablestatic Stringtostatic const StringinConnectivityCheckerConstantsto prevent accidental global mutation by consumers.- Windows
platformStatusStreamis now cached —WindowsRxConnectivityCheckernow lazily initialises a single broadcast stream (matching the behaviour ofMethodChannelRxConnectivityChecker) to prevent multiple redundant native channel subscriptions. - Linux D-Bus client lifecycle —
LinuxRxConnectivityCheckernow closes theDBusClientsocket when the stream is cancelled, preventing file-descriptor leaks on hot-restart or widget disposal.
Fixed #
- Null-safety crash in
NativeReachabilityValidator— replaced the force-unwrapclient!with a null-coalescing fallback (client ?? DefaultHttpClient()). Callers who constructNativeReachabilityValidatordirectly without passing a client no longer receive aNull check operator used on a null valuecrash at runtime. - Removed internal
project_starter_kitdependency — replacedDebugLogger(from a private monorepo package) withdart:developer'slog()function so the package builds correctly as a standalone pub.dev library. - Web validator parameter contract —
WebReachabilityValidatornow asserts (in debug mode) thatclientandheadersare null, making the previously silent no-op explicit and discoverable during development. - Corrected an issue where
throttleTimewas unintentionally tied to thecheckFrequencyinterval. This caused manual connectivity checks to be suppressed when triggered shortly after a periodic check, makingcheckConnectivity()appear unresponsive.