check_network 0.0.2 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:
- Rebuilding Widget if internet is not available
- Showing Snackbar if internet is not available
- Showing Dialog if internet is not available
- Redirecting to another screen if internet is not available
- etc.
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.
- First, you import the package to your dart file.
import 'package:check_network/check_network.dart';
- 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.