android_wifi_info 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

android_wifi_info #

Dart plugin package for accessing Android's WifiInfo from Flutter. Android-only plugin.

This is a Dart plugin package for accessing wifi information from Flutter and Dart. This is an Android-only plugin.

The plugin wraps the WifiInfo class and provides access to all of its methods. It describes the state of any Wifi connection that is active or is in the process of being set up.

References #

The plugin is published on Dart Pub pub.dartlang.org/packages/android_wifi_info

You can read the API reference on Dart Pub.

The source code is available on GitHub smaho-engineering/android_wifi_info.

This Flutter plugin is created by the SMAHO engineering team.

Usage #

import 'package:android_wifi_info/android_wifi_info.dart';

getNetworkInfo() async {
  final bssid = await AndroidWifiInfo.bssid;
  final ssid = await AndroidWifiInfo.ssid;
}

Example app #

For a working example app, see the example directory.

To view example screen record, click here

Documentation #

AndroidWifiInfo Flutter plugin's documentation

Combine with other plugins to access features cross-platform #

This plugin is intentionally supporting only Android. However, this doesn't mean you cannot use this plugin to create your own cross-platform utility module for fetching the details you need for your app.

For example, if you want to fetch the current WiFi's BSSID, you can combine it with ios_network_info package:

import 'dart:io';

import 'package:android_wifi_info/android_wifi_info.dart';
import 'package:ios_network_info/ios_network_info.dart';

get bssid {
  if (Platform.isAndroid) {
    return AndroidWifiInfo.bssid;
  } else if (Platform.isIOS) {
    return IosNetworkInfo.bssid;
  }
  throw Exception('WiFi BSSID is not supported on this platform');
}

To do #

This plugin is very much in progress.

There are some important tasks I'm still planning to do for the 1.x version release.

  • handle enums properly
  • related code, eg converting RSSI to something useful (scale)
  • don't forget to point users to how to convert int values to more traditional representations (ip)
  • Android Q? tx, rx link speed
  • could add links to the right sections in android docs
  • consider adding code snippets to the documentation
  • example app docs contains links and on tap could open the links in browser... but it's a bit of an overkill for an example app
  • make mac address work with proper permissions or at least document it

0.1.1 #

  • Fix br0k3n URL to the Pub

0.1.0 #

  • All WifiInfo methods are implemented except:
    • Android Q
    • methods with enum parameter or return value
  • All of these methods are documented
  • Example app
  • Documentation, READMEs, unit tests are in place

0.0.1 #

  • Initial release.
  • Still lots of todos, missing docs, readmes, examples. For 0.1.x, we'll have all of them

example/lib/main.dart

import 'dart:async';

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

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

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

class _MyAppState extends State<MyApp> {
  // Public methods
  Future<String> bssid;
  // TODO: detailedStateOf
  Future<int> frequency;
  Future<bool> ssidHidden;
  Future<int> ipAddress;
  Future<int> linkSpeed;
  Future<String> macAddress;
  Future<int> networkId;
  Future<int> rssi;
  Future<int> rxLinkSpeedMbps;
  Future<String> ssid;
  // TODO: supplicantState
  // Future<SupplicantState> supplicantState;
  Future<int> txLinkSpeedMbps;
  // Constants
  Future<String> frequencyUnits;
  Future<String> linkSpeedUnits;

  @override
  void initState() {
    fireAllFutures();
    super.initState();
  }

  fireAllFutures() {
    setState(() {
      // Public methods
      bssid = AndroidWifiInfo.bssid;
      frequency = AndroidWifiInfo.frequency;
      ssidHidden = AndroidWifiInfo.ssidHidden;
      ipAddress = AndroidWifiInfo.ipAddress;
      linkSpeed = AndroidWifiInfo.linkSpeed;
      macAddress = AndroidWifiInfo.macAddress;
      networkId = AndroidWifiInfo.networkId;
      rssi = AndroidWifiInfo.rssi;
      rxLinkSpeedMbps = AndroidWifiInfo.rxLinkSpeedMbps;
      ssid = AndroidWifiInfo.ssid;
      txLinkSpeedMbps = AndroidWifiInfo.txLinkSpeedMbps;
      // Constants
      frequencyUnits = AndroidWifiInfo.frequencyUnits;
      linkSpeedUnits = AndroidWifiInfo.linkSpeedUnits;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          appBar: AppBar(
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.refresh),
                onPressed: fireAllFutures,
              )
            ],
            title: Text(
              'android_wifi_info',
              style: TextStyle(
                fontFamily: 'monospace',
                fontWeight: FontWeight.w600,
              ),
            ),
            backgroundColor: Colors.lightGreen,
          ),
          body: ListView(
            children: <Widget>[
              // PUBLIC METHODS
              buildFutureListTile(
                future: bssid,
                name: 'bssid',
                description: Column(
                  children: <Widget>[
                    TText(
                        'Basic service set identifier (BSSID) of the current access point.'),
                    TText(
                        'Returns BSSID, in the form of a six-byte MAC address: XX:XX:XX:XX:XX:XX'),
                    TText(
                        'The BSSID may be null if there is no network currently connected.')
                  ],
                ),
                type: 'String',
              ),
              // TODO: detailedStateOf
              buildFutureListTile(
                  future: frequency,
                  name: 'frequency',
                  description: Column(
                    children: <Widget>[TText('Current WiFi frequency in MHz')],
                  ),
                  type: 'int'),
              buildFutureListTile(
                future: ssidHidden,
                name: 'ssidHidden',
                description: Column(
                  children: <Widget>[
                    TText('Shows whether the current network is hidden.'),
                    TText(
                        'true if this network does not broadcast its SSID, so an SSID-specific probe request must be used for scans.')
                  ],
                ),
                type: 'bool',
              ),
              buildFutureListTile(
                future: ipAddress,
                name: 'ipAddress',
                description: Column(
                  children: <Widget>[
                    TText('IP Address.'),
                  ],
                ),
                type: 'int',
              ),
              buildFutureListTile(
                future: linkSpeed,
                name: 'linkSpeed',
                description: Column(
                  children: <Widget>[
                    TText('Current link speed in Mbps.'),
                  ],
                ),
                type: 'int',
              ),
              buildFutureListTile(
                future: macAddress,
                name: 'macAddress',
                description: Column(
                  children: <Widget>[
                    TText('MAC Address'),
                    TText(
                        'Using these device identifiers is not recommended other than for high value fraud prevention and advanced telephony use-cases. For advertising use-cases, use AdvertisingIdClient\$Info#getId and for analytics, use InstanceId#getId.'),
                    // TODO: links
                  ],
                ),
                type: 'String',
              ),
              buildFutureListTile(
                future: networkId,
                name: 'networkId',
                description: Column(
                  children: [
                    TText('Network ID.'),
                    TText(
                        'Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. This method returns the ID for the currently connected network.')
                  ],
                ),
                type: 'int',
              ),
              buildFutureListTile(
                future: rssi,
                name: 'rssi',
                description: Column(
                  children: [
                    TText('Received Signal Strength Indicator.'),
                    TText(
                        'Returns the received signal strength indicator of the current 802.11 network, in dBm.')
                  ],
                ),
                type: 'int',
              ),
              /*
              buildFutureListTile(
                future: rxLinkSpeedMbps,
                name: 'rxLinkSpeedMbps',
                description: Column(
                  children: [Text('Current receive link speed in Mbps.')],
                ),
                type: 'int',
              ), */
              buildFutureListTile(
                future: ssid,
                name: 'ssid',
                description: Column(
                  children: <Widget>[
                    TText(
                        'Service set identifier (SSID aka WiFi Name) of the current 802.11 network.'),
                  ],
                ),
                type: 'String',
              ),
              // TODO: supplicantState
              /*
              buildFutureListTile(
                future: txLinkSpeedMbps,
                name: 'txLinkSpeedMbps',
                description: Column(
                  children: [
                    Text(
                        'Current transmit link speed in [linkSpeedUnits] (Mbps).')
                  ],
                ),
                type: 'int',
              ),*/
              // CONSTANTS
              buildFutureListTile(
                future: frequencyUnits,
                name: 'frequencyUnits',
                description: Column(
                  children: <Widget>[
                    TText(
                        'The unit in which frequency measurements expressed in this API.'),
                    TText('Constant Value: "MHz".'),
                    TText(
                        'As it\'s constant value, it doesn\'t really make much sense to call it all the time, but as the package decided to provide an interface to the WifiInfo class, frequencyUnits is also part of the API.'),
                  ],
                ),
                type: 'String',
              ),
              buildFutureListTile(
                future: linkSpeedUnits,
                name: 'linkSpeedUnits',
                description: Column(
                  children: <Widget>[
                    TText('The unit in which links speeds are expressed.'),
                    TText('Constant Value: "Mbps".'),
                    TText(
                        'As it\'s constant value, it doesn\'t really make much sense to call it all the time, but as the package decided to provide an interface to the WifiInfo class, linkSpeedUnits is also part of the API.'),
                  ],
                ),
                type: 'linkSpeedUnits',
              ),
            ],
          )),
    );
  }

  Widget buildFutureListTile({
    @required Future future,
    @required String name,
    @required Widget description,
    @required String type,
  }) {
    List<Widget> expansionTileChildren = [
      Padding(
        padding: EdgeInsets.all(8.0),
        child: Row(
          children: [
            Text('Type: '),
            Text(type, style: TextStyle(fontFamily: 'monospace')),
          ],
        ),
      ),
      Padding(padding: EdgeInsets.all(8.0), child: description),
    ];
    final nameWidget = Text(
      '$name ',
      style: TextStyle(
        fontWeight: FontWeight.bold,
        fontFamily: 'monospace',
      ),
    );

    return FutureBuilder(
      future: future,
      builder: (context, snapshot) {
        final titleWidget = Row(children: <Widget>[
          nameWidget,
          Text(
            '${snapshot.data}',
            style: TextStyle(fontFamily: 'monospace'),
          ),
        ]);
        if (snapshot.hasError) {
          return ExpansionTile(
            leading: Icon(Icons.error, color: Colors.red),
            title: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(type, style: TextStyle(fontFamily: 'monospace')),
                Text(name),
                Text(snapshot.error)
              ],
            ),
            children: [description, Text(snapshot.error)],
          );
        }
        switch (snapshot.connectionState) {
          case ConnectionState.active:
            return Text('active');
          case ConnectionState.done:
            return ExpansionTile(
              leading: snapshot.hasData
                  ? Icon(Icons.check_circle, color: Colors.green)
                  : Icon(Icons.error_outline, color: Colors.orange),
              title: titleWidget,
              children: expansionTileChildren,
            );
          case ConnectionState.none:
            return ExpansionTile(
              leading: Icon(Icons.help_outline, color: Colors.red),
              title: titleWidget,
              children: expansionTileChildren,
            );
          case ConnectionState.waiting:
            return ExpansionTile(
              leading: Icon(Icons.hourglass_empty, color: Colors.grey[400]),
              title: titleWidget,
              children: expansionTileChildren,
            );
        }
      },
    );
  }
}

class TText extends StatelessWidget {
  final text;

  TText(this.text, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => SizedBox(
        width: double.infinity,
        child: Container(child: Text(text, textAlign: TextAlign.left)),
      );
}

Use this package as a library

1. Depend on it

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


dependencies:
  android_wifi_info: ^0.1.1

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:android_wifi_info/android_wifi_info.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
99
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

Package is getting outdated. (-1.10 points)

The package was last published 52 weeks ago.

Dependencies

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