Search packages, repositories and app categories

GitHub repositoryajomuch92/simple-connection-checker

simple-connection-checker

ajomuch92/simple-connection-checker open-source repository details.

simple-connection-checker project cover
Stars
1
Forks
0
Last push (UTC)
Jan 27, 2025
Project status
Active

Original README

English project snapshot. Visit GitHub 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

Aarón J. Montes GitHub avatar
GitHub author

Aarón J. Montes ↗

System Engineer/Software developer

KSSComayagua, HondurasOfficial website ↗
LanguagesDartHTMLSwiftKotlinObjective-C

Packages published by this repository

Dependencies used

Dependency list 3 items

  • flutter{"sdk":"flutter"}
  • http^1.3.0
  • flutter_testDevelopment{"sdk":"flutter"}

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗