NetworkService class
Tracks device connectivity and publishes changes as a broadcast stream.
This is a process-wide singleton because the underlying platform channel is itself global. Unlike NetGuard 1.x, dispose fully resets the singleton so a later instance access returns a usable service instead of one wrapping a closed StreamController.
Properties
- currentStatus → NetworkStatus
-
Current connectivity state.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- initializationError → String?
-
The failure from the last unsuccessful initialize, if any.
no setter
- isInitialized → bool
-
Whether initialize has completed successfully.
no setter
- isOffline → bool
-
Whether the device is known to be offline.
no setter
- isOnline → bool
-
Whether a usable connection is available.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
statusStream
→ Stream<
NetworkStatus> -
Broadcast stream of connectivity changes.
no setter
Methods
-
configureProbe(
ConnectivityProbe probe) → void -
Install a reachability probe. Pass an empty ConnectivityProbe to
trust
connectivity_plusalone. -
dispose(
) → void - Stop monitoring and release resources.
-
getConnectionInfo(
) → Map< String, dynamic> - Diagnostic snapshot of the current state.
-
initialize(
) → Future< bool> - Begin monitoring connectivity.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → Future< void> - Re-check connectivity immediately.
-
toString(
) → String -
A string representation of this object.
inherited
-
waitForConnection(
{Duration timeout = const Duration(minutes: 2)}) → Future< bool> -
Wait until the device is online, or until
timeoutelapses.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → NetworkService
-
The shared service, created on first access.
no setter
Static Methods
-
overrideInstance(
{Connectivity? connectivity, ConnectivityProbe? probe}) → void - Replace the singleton, for tests or to inject a custom probe.