Flutter Confirm Connection Network
In this guide, we will learn how to implement the network Connectivity Status in Flutter by using the external package name confirm_connection_network. This plugin allows Flutter apps to discover network connectivity. For example, when you are connected or disconnected from wifi. this package will not tell us if we have or not internet connection. In this example, we are going to show you how to check the internet connection in Flutter. we will learn to check if the device’s internet connection is online or offline , To check the network connectivity status in a Flutter app, you can use the confirmConnection Function, which is provided by the confirm_connection_network package. Here’s an example of how you could use it:
Usage
First, add confirm_connection_network
as a dependency in your pubspec.yaml file.
dependencies:
confirm_connection_network: ^0.1.1
Don't forget to flutter pub get
.
Then import:
import 'package:confirm_connection_network/confirm_connection_network.dart';
Now you can create FlutterNetworkConnectivity object and use its methods
checkConnection()async{
if (await ConfirmConnection.confirmConnection()){
print("you are online");
} else {
print("you are offline");
}
}
To Checking Network connection Status
checkConnection()async{
if (await ConfirmConnection.confirmConnection()){
print("you are online");
} else {
print("you are offline");
}
}
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" />
Minimum SDK Version 16
iOS
Uses NetworkMonitor, minimum required version 10.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.