AppConnectivity class
Zero-dependency network connectivity and internet reachability monitor.
Unlike standard OS interface checkers which only verify if Wi-Fi or cellular
is toggled on, AppConnectivity checks actual end-to-end internet reachability
via low-overhead socket lookups on dart:io platforms and browser network
state on Flutter Web.
It provides a reactive isOnline observable (Rx<bool>) for declarative UI rebuilds,
a broadcast stream, in-flight deduplication, parallel host racing, and automatic
lifecycle pause/resume to eliminate background battery drain.
Properties
-
customChecker
↔ Future<
bool> Function()? -
Optional custom connectivity test resolver (primarily used for unit testing).
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isOffline → bool
-
Returns
trueif the device is currently confirmed offline.no setter -
isOnline
→ Rx<
bool> -
Reactive observable tracking whether the device currently has internet reachability.
final
-
onConnectivityChanged
→ Stream<
bool> -
Stream of connectivity status changes.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkConnection(
{List< String> ? hosts, Duration timeout = const Duration(seconds: 3)}) → Future<bool> - Performs a network reachability check and updates isOnline.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
) → void - Resets connectivity state and stops monitoring (primarily used for test teardown).
-
startMonitoring(
{Duration interval = const Duration(seconds: 5), List< String> ? hosts, Duration timeout = const Duration(seconds: 3)}) → void - Starts background periodic connectivity monitoring.
-
stopMonitoring(
) → void - Stops the background connectivity monitor and cancels its timer and lifecycle listener.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → AppConnectivity
-
Singleton instance of AppConnectivity.
no setter
Constants
-
defaultLookupHosts
→ const List<
String> - Default reliable IP endpoints used for quick socket connectivity pings (port 53 DNS).