Connect To A Specific Wifi Network In Flutter Dart
Hey everyone, in this article we will cover….
How to connect to a specific wi-fi network with SSID name and will check for wi-fi is enabled or not in device rather than internet connectivity.
If you want to check for wi-fi of device is enabled or not either internet is available or not. Then this plugin helps us to know the same.
For now this plugin is not available for IOS this time i’m writing this article, but this will be available soon inside the same package/plugin for IOS as well.
So, let’s start & add the dependency in your
pubspec.yaml
wifi_configuration_2: ^1.1.2+1
get dependency using.
$ flutter pub add wifi_configuration_2
imports
import 'package:wifi_configuration_2/wifi_configuration_2.dart';
Add below permissions to your…
Manifist.xml
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Now in your file where you wanna check for the enabled wifi connection just add the code snippet below, this will check either wifi is enabled or not for the application on the particular device.
await wifiConfiguration.isWifiEnabled();
Now, we will connect with the specific wi-fi using ssidname & password of any particular wi-fi. This will provide the response for established connection. To establish the connection with this ssidname you also have an internet connection available on this specific wi-fi.
await wifiConfiguration!.connectToWifi("SSID name", "password","your application package name here...");
We can also enable or disable the wi-fi using the same plugin like that…
// enable wifienableWifi() {
wifiConfiguration.enableWifi();
}// disable wifidisableWifi() {
wifiConfiguration.disableWifi();
}
You can use these methods where you wanna implement that functionalities in your screens. This will helps you to connect with a specific wi-fi. Here all i can show you how to connect with a specific wi-fi. I hope this article will help you to implement the related functionalities.
For more reference click on the link here.
If You Liked This Article, Don’t Forget To Clap.
Happy Coding !!