wifi_scan 0.4.0 copy "wifi_scan: ^0.4.0" to clipboard
wifi_scan: ^0.4.0 copied to clipboard

Flutter plugin to scan for nearby visible WiFi access points.

WiFiFlutter| wifi_scan

Flutter Network pub.dev pub points popularity likes


This plugin allows Flutter apps to scan for nearby visible WiFi access points.

This plugin is part of WiFiFlutter suite, enabling various WiFi services for Flutter.

Platform Support #

Platform Status Min. Version API Notes
Android ✔️ 16 (J) Scan related APIs in WifiManager [Guide] For SDK >= 26(O) scans are throttled.
iOS ✔️ 9.0 No public API, requires special entitlements from Apple Stub implementation with sane returns.

Usage #

The entry point for the plugin is the singleton instance WiFiScan.instance.

Start scan #

You can trigger full WiFi scan with WiFiScan.startScan API, as shown below:

void _startScan() async {
  // check platform support and necessary requirements
  final can = await WiFiScan.instance.canStartScan(askPermissions: true);
  switch(can) {
    case CanStartScan.yes:
      // start full scan async-ly
      final isScanning = await WiFiScan.instance.startScan();
      //...
      break;
    // ... handle other cases of CanStartScan values
  }
}

For more details, you can read documentation of WiFiScan.startScan, WiFiScan.canStartScan and CanStartScan.

Get scanned results #

You can get scanned results with WiFiScan.getScannedResults API, as shown below:

void _getScannedResults() async {
  // check platform support and necessary requirements
  final can = await WiFiScan.instance.canGetScannedResults(askPermissions: true);
  switch(can) {
    case CanGetScannedResults.yes:
      // get scanned results
      final accessPoints = await WiFiScan.instance.getScannedResults();
      // ...
      break;
    // ... handle other cases of CanGetScannedResults values
  }
}

NOTE: getScannedResults API can be used independently of startScan API. This returns the latest available scanned results.

For more details, you can read documentation of WiFiScan.getScannedResults, WiFiAccessPoint, WiFiScan.canGetScannedResults and CanGetScannedResults.

Get notified when scanned results available #

You can get notified when new scanned results are available with WiFiScan.onScannedResultsAvailable API, as shown below:

// initialize accessPoints and subscription
List<WiFiAccessPoint> accessPoints = [];
StreamSubscription<List<WiFiAccessPoint>>? subscription;

void _startListeningToScannedResults() async {
  // check platform support and necessary requirements
  final can = await WiFiScan.instance.canGetScannedResults(askPermissions: true);
  switch(can) {
    case CanGetScannedResults.yes:
      // listen to onScannedResultsAvailable stream
      subscription = WiFiScan.instance.onScannedResultsAvailable.listen((results) {
        // update accessPoints
        setState(() => accessPoints = results);
      });
      // ...
      break;
    // ... handle other cases of CanGetScannedResults values
  }
}

// make sure to cancel subscription after you are done
@override
dispose() {
  super.dispose();
  subscription?.cancel();
}

Additionally, WiFiScan.onScannedResultsAvailable API can also be used with Flutter's StreamBuilder widget.

NOTE: onScannedResultsAvailable API can be used independently of startScan API. The notification can also be result of a full scan performed by platform or other app.

For more details, you can read documentation of WiFiScan.onScannedResultsAvailable, WiFiAccessPoint, WiFiScan.canGetScannedResults and CanGetScannedResults.

Resources #

Issues and feedback #

Please file WiFiFlutter specific issues, bugs, or feature requests in our issue tracker.

To contribute a change to this plugin, please review plugin checklist for 1.0, our contribution guide and open a pull request.

Contributors ✨ #

Thanks goes to these 💖 people for their contributions.

This project follows the all-contributors specification. Contributions of any kind welcome!

62
likes
0
pub points
96%
popularity

Publisher

verified publisherflutternetwork.dev

Flutter plugin to scan for nearby visible WiFi access points.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on wifi_scan