Search packages, repositories and app categories

simple_connection_checker cover
Package detailsv0.3.4

simple_connection_checker

A simple package to check when the device is connected (connectivity) to internet. Also provide a method to listen for connection status changes.

AndroidiOSmacOSWindowsLinux
30-day downloads
8.3K
Likes
34
Pub points
160

Install package

flutter pub add simple_connection_checker

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight Flutter package that enables simple detection of internet connectivity status on multiple platforms. It provides a straightforward way to check if the device is connected to the internet and offers a stream to listen for real-time changes in connection status. Ideal for apps needing reliable network state monitoring without complex setup. The package supports Android, iOS, macOS, Windows, and Linux, making it versatile for cross-platform development.

Use cases

  • Checking internet connectivity before API calls
  • Monitoring network status changes in real time
  • Ensuring offline mode handling
  • Displaying network status indicators
  • Validating user actions based on connectivity
  • Preventing failed requests during poor network conditions

Key features

  • Simple API for connectivity checks
  • Stream-based connection status listening
  • Cross-platform support
  • Lightweight and easy to integrate
  • Real-time updates on connection changes
  • No additional dependencies

Suitable for

  • Basic connectivity monitoring
  • Apps requiring network awareness
  • Developers seeking minimal setup
  • Cross-platform mobile and desktop apps
  • Projects with limited network logic
  • Prototypes and quick implementations

Considerations

  • Does not handle Wi-Fi vs cellular distinction
  • Limited to online/offline state only
  • No built-in retry mechanisms
  • Relies on system-level connectivity APIs
  • May require permission handling on some platforms
  • Not suitable for advanced network diagnostics

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Simple Connection Checker

A simple package to check when the device is connected (connectivity) to internet. Also provide a method to listen for connection status changes.

Demo

Instalation

Include simple_connection_checker in your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  simple_connection_checker: version

Usage

To use this package, just import it into your file and call the static method isConnectedToInternet as follows:

import 'package:simple_connection_checker/simple_connection_checker.dart';

...

bool isConnected = await SimpleConnectionChecker.isConnectedToInternet();

...

Note: You can pass an optional parameter named lookUpAddress to pass an especific URL to make the lookup operation and check the internet connection. By default, this value is www.google.com. Do not use the protocol on the URL string passed (http:// or https://).

New 💥

  • A beta version to use with web
  • Now you can listen for internet connection changes. Here is the example
import 'package:simple_connection_checker/simple_connection_checker.dart';

...
StreamSubscription? subscription;
bool? _connected;

@override
void initState() {
  super.initState();
  SimpleConnectionChecker _simpleConnectionChecker = SimpleConnectionChecker()
      ..setLookUpAddress('pub.dev'); //Optional method to pass the lookup string
  subscription = _simpleConnectionChecker.onConnectionChange.listen((connected) {
    setState(() {
      _connected = connected;
    });
  });
}

@override
void dispose() {
  subscription?.cancel();
  super.dispose();
}

...

Note: Don't forget to cancel the subscription

Demo

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.