simple_connection_checker 0.3.4 copy "simple_connection_checker: ^0.3.4" to clipboard
simple_connection_checker: ^0.3.4 copied to clipboard

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

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
copied to clipboard

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();

...

copied to clipboard

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();
}

...

copied to clipboard

Note: Don't forget to cancel the subscription

Demo #

32
likes
160
points
3.96k
downloads

Publisher

verified publisherajomuch92.site

Weekly Downloads

2024.09.23 - 2025.04.07

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on simple_connection_checker