NyConnectivity class
Connectivity helper for checking network status.
Provides static methods to check connectivity and listen for changes.
Example:
// Check if online
if (await NyConnectivity.isOnline()) {
// Make network request
}
// Get current connection type
final status = await NyConnectivity.status();
if (status.contains(ConnectivityResult.wifi)) {
print('Connected via WiFi');
}
// Listen to connectivity changes
NyConnectivity.stream().listen((results) {
print('Connection changed: $results');
});
Constructors
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 Methods
-
connectionTypeString(
) → Future< String> - Get a human-readable connection type string.
-
isBluetooth(
) → Future< bool> - Check if connected via Bluetooth.
-
isEthernet(
) → Future< bool> - Check if connected via Ethernet.
-
isMobile(
) → Future< bool> - Check if connected via mobile data.
-
isOffline(
) → Future< bool> - Check if the device is offline.
-
isOnline(
) → Future< bool> - Check if the device has any network connection.
-
isVpn(
) → Future< bool> - Check if connected via VPN.
-
isWifi(
) → Future< bool> - Check if connected via WiFi.
-
status(
) → Future< List< ConnectivityResult> > - Get the current connectivity status.
-
stream(
) → Stream< List< ConnectivityResult> > - Get a stream of connectivity changes.
-
when<
T> ({required Future< T> online(), required Future<T> offline()}) → Future<T> - Execute different callbacks based on connectivity status.
-
whenOnline<
T> (Future< T> callback()) → Future<T?> - Execute a callback only when online.