wifi_configuration_2 1.0.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

wifi_configuration_2 #

Wifi plugin for flutter

Getting Started #

This plugin is a updated version of wifi_configuration This plugin allows Flutter apps to get available WifiNetwork list where you can get almost all the information about AP accessing to WifiNetwork object, user can connect to wifi with ssid and password. This plugin works only for Android. iOS will be released later.

Sample usage to check current status:

Note :- This plugin requires the location permission to auto enable the wifi if android version is above 9.0.

For Android : - Add below Permissions to your manifist.xml file -

    <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" />

Import package

import 'wifi_configuration_2.dart';

Initialize plugin

WifiConfiguration wifiConfiguration = WifiConfiguration();

Check whether Wifi is enabled or disabled

wifiConfiguration.isWifiEnabled().then((value) {
      print('Is wifi enabled: ${value.toString()}');
    });

Get WIFI network list

 wifiNetworkList = await wifiConfiguration.getWifiList();
    setState(() {});

Check your connection is slow or fast

wifiConfiguration.isConnectionFast().then((value){
                          print('Connection type: ${value.toString()}');
                        });

Check your connection type

  wifiConfiguration.getConnectionType().then((value){
                          print('Connection type: ${value.toString()}');
                        });

Enable wifi

 wifiConfiguration.enableWifi();

Disable Wifi

wifiConfiguration.disableWifi();

Check internet connection

 wifiConfiguration.checkConnection().then((value){
      print('Value: ${value.toString()}');
    });

Check signal level of every network #

ListView example of wifiNetworks

SignalLevel = 5 is maximum

SignalLevel = 0 is minimum

ListView.builder(
                      itemBuilder: (context, index) {
                        WifiNetwork wifiNetwork = wifiNetworkList[index];
                        return ListTile(
                          leading: Text(wifiNetwork.signalLevel),
                          title: Text(wifiNetwork.ssid),
                          subtitle: Text(wifiNetwork.bssid),
                        );
                      },
                      itemCount: wifiNetworkList.length,
                    ),
    WifiConnectionStatus connectionStatus = await wifiConfiguration.connectToWifi("ssidName", "passName", "your android packagename");
    //This will return state of a connection
    //Package name is required to redirect user to application permission settings page to let user allow location permission
    //in case connecting with wifi
  
  
        switch (connectionStatus) {
              case WifiConnectionStatus.connected:
                print("connected");
                break;
        
              case WifiConnectionStatus.alreadyConnected:
                print("alreadyConnected");
                break;
        
              case WifiConnectionStatus.notConnected:
                print("notConnected");
                break;
        
              case WifiConnectionStatus.platformNotSupported:
                print("platformNotSupported");
                break;
        
              case WifiConnectionStatus.profileAlreadyInstalled:
                print("profileAlreadyInstalled");
                break;
        
              case WifiConnectionStatus.locationNotAllowed:
                print("locationNotAllowed");
                break;
            }
  
  
        var listAvailableWifi = await wifiConfiguration.getWifiList();
          //If wifi is available then device will get connected
          //In case of ios you will not get list of connected wifi an empty list will be available
          //As Apple does not allow to scan the available hotspot list
          //If you try to access with private api's then apple will reject the app
  
  
        bool isConnected = await wifiConfiguration.isConnectedToWifi("ssidName");
        //to get status if device connected to some wifi
        
        String isConnected = await wifiConfiguration.connectedToWifi();
                //to get current connected wifi name
        

If user has not aloowed the location permission for this app then it will ask everytime app try to connect to wifi for the location permission.

When you use connection on iOS (iOS 11 and above only)

  1. 'Build Phases' -> 'Link Binay With Libraries' add 'NetworkExtension.framework'

  2. in 'Capabilities' open 'Hotspot Configuration'

  3. If you device is iOS12, in 'Capabilities' open 'Access WiFi Information'

If you want to use Wifi.list on iOS,

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

1.0.9 #

Check whether Wifi is enabled or disabled #

Check internet connection #

Check signal level of every network #

ListView example of wifiNetworks

SignalLevel = 5 is maximum

SignalLevel = 0 is minimum

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:wifi_configuration_2/wifi_configuration_2.dart';

WifiConfiguration wifiConfiguration;

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

//enum wifiStatus {
//  conected,
//alreadyConnected,.
//notConnected ,
//platformNotSupported,
//profileAlreadyInstalled,
//
//}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  List<WifiNetwork> wifiNetworkList = List();
  bool isLoaded = false;

  @override
  void initState() {
    super.initState();
    wifiConfiguration = WifiConfiguration();
    //getConnectionState();
    checkConnection();
  }

  void getConnectionState() async {
    WifiConnectionStatus connectionStatus =
        await wifiConfiguration.connectToWifi(
            "DarkBe@rs", "DarkBe@rs", "com.example.wifi_configuration_example");
    print("is Connected : ${connectionStatus}");
//
//
    switch (connectionStatus) {
      case WifiConnectionStatus.connected:
        print("connected");
        break;

      case WifiConnectionStatus.alreadyConnected:
        print("alreadyConnected");
        break;

      case WifiConnectionStatus.notConnected:
        print("notConnected");
        break;

      case WifiConnectionStatus.platformNotSupported:
        print("platformNotSupported");
        break;

      case WifiConnectionStatus.profileAlreadyInstalled:
        print("profileAlreadyInstalled");
        break;

      case WifiConnectionStatus.locationNotAllowed:
        print("locationNotAllowed");
        break;
    }
//
//    bool isConnected = await WifiConfiguration.isConnectedToWifi("DBWSN5");
    // String connectionState = await WifiConfiguration.connectedToWifi();
    //   print("coneection status ${connectionState}");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: wifiNetworkList.isEmpty && isLoaded
            ? Center(
                child: FlatButton(
                  color: Colors.red,
                  child: Text("connect"),
                  onPressed: () async {
                    WifiConnectionObject connectionStatus =
                        await wifiConfiguration.connectedToWifi();
                    print("Ip address : ${connectionStatus.ip}");
                    wifiConfiguration.getConnectionType().then((value) {
                      print('Connection type: ${value.toString()}');
                    });
                    wifiConfiguration.isConnectionFast().then((value) {
                      print('Is connection fast: ${value.toString()}');
                    });
                  },
                ),
              )
            : Column(
                children: <Widget>[
                  FlatButton(
                      onPressed: () {
                        WifiConfiguration wifiConfiguration = WifiConfiguration();
                        wifiConfiguration.enableWifi();
                      },
                      child: Text('Wifi enable')),
                  FlatButton(
                      onPressed: () {
                        WifiConfiguration wifiConfiguration = WifiConfiguration();
                        wifiConfiguration.disableWifi();
                      },
                      child: Text('Wifi disable')),
                  FlatButton(
                      onPressed: () {
                        wifiConfiguration.getConnectionType().then((value) {
                          print('Connection type: ${value.toString()}');
                        });

                        wifiConfiguration.isConnectionFast().then((value) {
                          print('Connection type: ${value.toString()}');
                        });
                      },
                      child: Text('Print information')),
                  Divider(),
                  Expanded(
                    child: ListView.builder(
                      itemBuilder: (context, index) {
                        WifiNetwork wifiNetwork = wifiNetworkList[index];
                        return ListTile(
                          leading: Text(wifiNetwork.signalLevel),
                          title: Text(wifiNetwork.ssid),
                          subtitle: Text(wifiNetwork.bssid),
                        );
                      },
                      itemCount: wifiNetworkList.length,
                    ),
                  ),
                ],
              ),
      ),
    );
  }

  void checkConnection() async {
    wifiConfiguration.isWifiEnabled().then((value) {
      print('Is wifi enabled: ${value.toString()}');
    });

    wifiConfiguration.checkConnection().then((value) {
      print('Value: ${value.toString()}');
    });

    WifiConnectionObject wifiConnectionObject =
        await wifiConfiguration.connectedToWifi();
    if (wifiConnectionObject != null) {
      getWifiList();
    }
  }

  Future<void> getWifiList() async {
    wifiNetworkList = await wifiConfiguration.getWifiList();
    print('Network list lenght: ${wifiNetworkList.length.toString()}');
    setState(() {});
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  wifi_configuration_2: ^1.0.9

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:wifi_configuration_2/wifi_configuration_2.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
64
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:wifi_configuration_2/wifi_configuration_2.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:wifi_configuration_2/wifi_configuration_2.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:wifi_configuration_2/wifi_configuration_2.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:wifi_configuration_2/wifi_configuration_2.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [wifi_configuration_2] that is in a package requiring null.

Health suggestions

Fix lib/wifi_configuration_2.dart. (-0.50 points)

Analysis of lib/wifi_configuration_2.dart reported 1 hint:

line 25 col 33: This function has a return type of 'Future

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test