check_network 0.0.2 copy "check_network: ^0.0.2" to clipboard
check_network: ^0.0.2 copied to clipboard

Checking Internet and Testing Server availability with just few line.

check_network #

Checking Internet availability by pinging DNS servers to check if the Internet connection is available or not.

Table of contents #

General info #

This package is simply ping DNS sever to check if availability of internet is valid one or not. It is useful because by wrapping MaterialApp widget, with InternetStatusProvider will give access to Stream of internet status which then can be used to perform any action based on internet status. Such as:

Show Snackbar

Setup #

To use this package, you need to install it first. You can install it by running this command:

flutter pub add check_network

Or you can add this to your pubspec.yaml file:

dependencies:

 check_network: ^0.0.1

Features #

List of features ready and TODOs for future development

  • Check internet availability

To-do list:

  • Add option to check availability of specific domain address
  • Support internet speed test

How to use #

To see full example, please check the example folder.

  1. First, you import the package to your dart file.
import 'package:check_network/check_network.dart';
  1. Warp the Top Most Widget with the InternetStatusProvider. This will provide the Stream of InternetStatus to all children widgets.
InternetStatusProvider(
 currentInternetStatus: CurrentInternetStatus(waitOnConnectedStatusInSeconds: 5),
 child: const MyApp(),
),

Now we will see how to rebuild the widget when internet status changes.

Rebuild Widget #

Have a Scaffold with StreamBuilder pass InternetStatusProvider.of(context).onStatusChange to stream parameter that will give access to Internet Status. And, now simple pass a function that return a widget based on the current internet status which will get recalled when internet status changes.

 return Scaffold(
      body: StreamBuilder<InternetStatus>(
        stream: InternetStatusProvider.of(context).onStatusChange,
        builder: (context, snapshot) {
          return Center(child: internetStatusWidgetBuilder(snapshot.data));
        },
      ),
    );

And, that's it we are done. Now, every time the internet status changes, the widget will be rebuilt. Please see the example in the example for full code and many more examples.

Acknowledgements #

NOTE: This package is a continuation and took inspiration from data_connection_checker.

I would like to appreciate

  • Dart team for creating such a great language.

  • Flutter team for creating such a great framework.

  • Very Good Ventures team for creating such a great open source project and packages.

  • Flutter Community team for amazing packages and resources.

2
likes
150
points
69
downloads

Publisher

unverified uploader

Weekly Downloads

Checking Internet and Testing Server availability with just few line.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

connectivity_plus, flutter

More

Packages that depend on check_network