isOnline function

  1. @Riverpod(keepAlive: true)
Stream<bool> isOnline(
  1. Ref<Object?> ref
)

Streams true when the device has any active network interface, false when fully offline.

Backed by connectivity_plus. Emits the current state immediately on subscription, then updates as the OS reports interface changes. Note this only reflects whether a network is configured — it doesn't probe reachability of any specific endpoint, so a flaky cellular connection can still report true while individual requests time out.

Consumers (offline banner, auto-suggest hook) treat false as the definitive offline signal but should still expect cloud AI calls to fail under degraded true conditions.

Implementation

@Riverpod(keepAlive: true)
Stream<bool> isOnline(Ref ref) async* {
  final connectivity = Connectivity();
  yield _isOnline(await connectivity.checkConnectivity());
  await for (final results in connectivity.onConnectivityChanged) {
    yield _isOnline(results);
  }
}