UNetwork class abstract

Connection state on all 6 platforms: online, wifi/cellular/vpn, metered, speed, real internet checks, change streams. if (UNetwork.isOffline) …

Constructors

UNetwork()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

cellularGeneration → String?
Mobile generation "2g"/"3g"/"4g"/"5g" (Android, iOS; web effectiveType); null elsewhere.
no setter
downlinkKbps → int?
Estimated download speed in kbps (Android, web); null elsewhere.
no setter
interfaceName → String?
Active interface name, e.g. "wlan0", "en0"; null on web.
no setter
isBehindCaptivePortal → bool
True on Wi-Fi that wants a sign-in page first (hotel, airport); Android/Linux/Windows.
no setter
isBluetooth → bool
True when tethered over Bluetooth.
no setter
isCellular → bool
True on mobile data.
no setter
isConstrained → bool
True when Data Saver / Low Data Mode is on (Android, Apple, web Save-Data).
no setter
isEthernet → bool
True on a cable.
no setter
isFast → bool
True when good enough for video / big files (wifi, ethernet, 4G+, or fast web downlink).
no setter
isMetered → bool
True when data may cost money (mobile data, hotspot). if (!UNetwork.isMetered) autoDownload()
no setter
isOffline → bool
True when no network is connected.
no setter
isOnline → bool
True when a network is connected (instant, no request; use hasInternet() to be sure). if (UNetwork.isOnline) sync()
no setter
isRoaming → bool?
True when roaming; null when the platform cannot tell (Android only).
no setter
isUnmetered → bool
True when online on free data without a data saver: safe for big downloads.
no setter
isVpn → bool
True while a VPN is active (web: never detectable).
no setter
isWifi → bool
True on Wi-Fi.
no setter
listenable → ValueListenable<UNetworkStatus>
Network status for ValueListenableBuilder. ValueListenableBuilder(valueListenable: UNetwork.listenable, builder: (c, s, _) => Text("${s.primary}"))
no setter
offlineGrace ↔ Duration
How long "offline" must last before it is reported (hides short drops). UNetwork.offlineGrace = 2.seconds
getter/setter pair
onlineStream → Stream<bool>
Emits true/false only when going online or offline. UNetwork.onlineStream.listen((on) => on ? retry() : null)
no setter
probeUrls ↔ List<Uri>?
URLs hasInternet() pings; null means your baseUrl + 2 public hosts. Set it to use your own. UNetwork.probeUrls = [Uri.parse("https://api.x.com/health")]
getter/setter pair
rttMs → int?
Estimated round trip in ms (web only).
no setter
signalStrength → int?
Wi-Fi/cell signal in dBm (Android only).
no setter
status → UNetworkStatus
Full snapshot (types, metered, roaming, speed, captive portal…). UNetwork.status.types
no setter
stream → Stream<UNetworkStatus>
Emits the full status every time the network changes. UNetwork.stream.listen((s) => print(s.primary))
no setter
type → UNetworkType?
Main connection type (wifi, cellular, ethernet…); null when offline.
no setter
types → Set<UNetworkType>
Every connection type in use, e.g. {wifi, vpn}.
no setter
uplinkKbps → int?
Estimated upload speed in kbps (Android); null elsewhere.
no setter

Static Methods

addresses({bool includeLoopback = false}) → Future<List<UNetworkAddress>>
Every IP address of this device (empty on web). await UNetwork.addresses()
dispose() → Future<void>
Stops watching the network.
hasInternet({bool force = false, Duration timeout = const Duration(seconds: 5)}) → Future<bool>
True when the internet really answers (pings your baseUrl + 2 public hosts, cached 5s). if (await UNetwork.hasInternet()) …
init() → Future<void>
Starts watching the network; initU() already does it.
listen(void onChange(UNetworkStatus status)) → StreamSubscription<UNetworkStatus>
Calls onChange on every network change; cancel the returned subscription in dispose(). final sub = UNetwork.listen(update);
localIp() → Future<String?>
Local IPv4, e.g. "192.168.1.20" (null on web). await UNetwork.localIp()
refresh() → Future<UNetworkStatus>
Reads the state from the OS again right now. await UNetwork.refresh()
whenOnline({Duration? timeout}) → Future<void>
Waits until the device is online (timeout throws TimeoutException). await UNetwork.whenOnline(); upload();