Last updated:
0 purchases
flutter network connectivity
Flutter Network Connectivity #
A flutter plugin to check for Internet Availability as a stream based on network connectivity status, periodic interval or on call.
Usage #
First, add flutter_network_connectivity as a dependency in your pubspec.yaml file.
dependencies:
flutter_network_connectivity: ^0.0.6
copied to clipboard
Don't forget to flutter pub get.
Then import:
import 'package:flutter_network_connectivity/flutter_network_connectivity.dart';
copied to clipboard
Now you can create FlutterNetworkConnectivity object and use its methods
FlutterNetworkConnectivity flutterNetworkConnectivity =
FlutterNetworkConnectivity(
isContinousLookUp: true, // optional, false if you cont want continous lookup
lookUpDuration: const Duration(seconds: 5), // optional, to override default lookup duration
lookUpUrl: 'example.com', // optional, to override default lookup url
);
copied to clipboard
To Check for Stream of Network Connectivity Status #
_flutterNetworkConnectivity.getInternetAvailabilityStream().listen((isInternetAvailable) {
// do something
});
copied to clipboard
Then Register Availability Listener after setting up Stream Listerer
await _flutterNetworkConnectivity.registerAvailabilityListener();
copied to clipboard
Unregister on dispose
await _flutterNetworkConnectivity.unregisterAvailabilityListener();
copied to clipboard
To Check for Internet Availability on Call #
bool _isNetworkConnectedOnCall = await
_flutterNetworkConnectivity.isInternetConnectionAvailable();
copied to clipboard
Examples #
Simple usage example can be found in the example folder.
Android
Uses permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
copied to clipboard
Minimum SDK Version 16
iOS
Uses NetworkMonitor, minimum required version 12.0
Demo
About #
This plugin uses NetworkCapabilities for Android and NetworkMonitor for iOS to check for network connectivity status.
Contributing? #
You're always welcome. See Contributing Guidelines. You can also take a look at Status Tracker to know more information about current or pending features/issues.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.