universal_internet_checker

Creator: coderz1093

Last updated:

0 purchases

universal_internet_checker Image
universal_internet_checker Images
Add to Cart

Description:

universal internet checker

Universal Internet Checker #
Listenable class to check internet connectivity in Web and Mobile
(not tested on desktop yet)
You can also use this in a StreamProvider to give network awareness to your entire app.
Installation #
Include universal_internet_checker in your pubspec.yaml file
or add it from pub:
flutter pub add universal_internet_checker
copied to clipboard
Usage #
To use this package, just import it into your file and call the static method checkInternet as follows:
import 'package:universal_internet_checker/universal_internet_checker.dart';

...

ConnectionStatus status = await UniversalInternetChecker.checkInternet();

...

copied to clipboard
Note: You can set the static variable "checkAddress" to a specific URL to make the operation and check the internet connection. By default, this value is www.google.com. Do not include (http:// or https://) or any subdirectory in your address
UniversalInternetChecker.checkAddress = 'www.example.com';
copied to clipboard
Note: You can listen for internet connection changes. Here is the example
import 'package:universal_internet_checker/universal_internet_checker.dart';

...
StreamSubscription? subscription;
ConnectionStatus? _status;

@override
void initState() {
super.initState();
subscription = UniversalInternetChecker.onConnectionChange.listen((status) {
setState(() {
_status = status;
});
});
}

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

...

copied to clipboard
Note: If you're using provider, use
StreamProvider<ConnectionStatus>(
create: (context) => UniversalInternetChecker().onConnectionChange,
initialData: ConnectionStatus.unknown)

copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.