NetworkReachability class final

The central entry point for the Network Reachability library.

This service provides a robust, high-level API for monitoring and validating network connectivity. It handles complex logic such as request coalescing, caching, and resilience patterns like the circuit breaker.

Core Features:

  • Manual Checks: Trigger precise network probes using check.
  • Security Guard: Protect sensitive operations from insecure networks using guard.
  • Real-time Monitoring: Listen to connectivity changes via onStatusChange.
  • Lifecycle Awareness: Automatically manages battery efficiency by pausing background checks when the app is minimized.

Example Usage:

 1. Initialize at app startup
await NetworkReachability.init();

 2. Perform a one-time check
final report = await NetworkReachability.instance.check();
print('Connected: ${report.status.isConnected}, Quality: ${report.status.quality}');

 3. Protect an API call
try {
  await NetworkReachability.instance.guard(
    action: () => myApi.fetchData(),
    minQuality: ConnectionQuality.good,
  );
} on NetworkReachabilityException catch (e) {
  print('Operation blocked: ${e.message}');
}
Mixed-in types

Properties

hashCode int
The hash code for this object.
no setterinherited
onStatusChange Stream<NetworkStatus>
A stream that emits NetworkStatus updates whenever a periodic check completes.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

check({bool forceRefresh = false}) Future<NetworkReport>
Performs a comprehensive network check.
checkForCaptivePortal({required BigInt timeoutMs}) Future<CaptivePortalStatus>
Detects if the current network is a "Captive Portal" (e.g., public WiFi login page).
checkTarget({required NetworkTarget target}) Future<TargetReport>
Performs a targeted reachability probe against a single endpoint.
detectDnsHijacking({required String domain}) Future<bool>
Checks for potential DNS tampering by comparing system results against trusted resolvers.
detectSecurityAndNetworkType() Future<(SecurityFlagsResult, ConnectionType)>
Inspects active network interfaces to determine connectivity type and security status.
didChangeAccessibilityFeatures() → void
Called when the system changes the set of currently active accessibility features.
inherited
didChangeAppLifecycleState(AppLifecycleState state) → void
Observes Flutter's app lifecycle to manage battery consumption.
override
didChangeLocales(List<Locale>? locales) → void
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
inherited
didChangeMetrics() → void
Called when the application's dimensions change. For example, when a phone is rotated.
inherited
didChangePlatformBrightness() → void
Called when the platform brightness changes.
inherited
didChangeTextScaleFactor() → void
Called when the platform's text scale factor changes.
inherited
didChangeViewFocus(ViewFocusEvent event) → void
Called whenever the PlatformDispatcher receives a notification that the focus state on a view has changed.
inherited
didHaveMemoryPressure() → void
Called when the system is running low on memory.
inherited
didPopRoute() Future<bool>
Called when the system tells the app to pop the current route, such as after a system back button press or back gesture.
inherited
didPushRoute(String route) Future<bool>
Called when the host tells the application to push a new route onto the navigator.
inherited
didPushRouteInformation(RouteInformation routeInformation) Future<bool>
Called when the host tells the application to push a new RouteInformation and a restoration state onto the router.
inherited
didRequestAppExit() Future<AppExitResponse>
Called when a request is received from the system to exit the application.
inherited
dispose() → void
Releases resources, removes observers, and shuts down the service.
guard<T>({required Future<T> action(), ConnectionQuality minQuality = ConnectionQuality.good}) Future<T>
Protects a network-sensitive action by validating the connection first.
handleCancelBackGesture() → void
Called when a predictive back gesture is canceled, indicating that no navigation should occur.
inherited
handleCommitBackGesture() → void
Called when a predictive back gesture is finished successfully, indicating that the current route should be popped.
inherited
handleStartBackGesture(PredictiveBackEvent backEvent) bool
Called at the start of a predictive back gesture.
inherited
handleStatusBarTap() → void
Called when the user taps the status bar on iOS, to scroll a scroll view to the top.
inherited
handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) → void
Called when a predictive back gesture moves.
inherited
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

instance NetworkReachability
Access the singleton instance of the network reachability service.
no setter

Static Methods

init({NetworkConfiguration? config, NetworkProbesRepository? probesRepository}) Future<void>
Initializes the Network Reachability engine.