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

outdated

Flutter plugin to scan for nearby visible WiFi access points.

WiFiFlutter| wifi_scan

analysis 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 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 {
  // start full scan async-ly
  final error = await WiFiScan.instance.startScan(askPermissions: true);
  if (error != null) {
    switch(error) {
      // handle error for values of StartScanErrors
    }
  }
}

For more details, you can read documentation of WiFiScan.startScan, StartScanErrors and Result<ValueType, ErrorType>.

Get scanned results #

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

void _getScannedResults() async {
  // get scanned results
  final result = await WiFiScan.instance.getScannedResults(askPermissions: true);
  if (result.hasError){
    switch (error){
      // handle error for values of GetScannedResultErrors
    }
  } else {
    final accessPoints = result.value;
    // ...
  }
}

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, GetScannedResultsErrors and Result<ValueType, ErrorType>.

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<Result<List<WiFiAccessPoint>, GetScannedResultErrors>>? subscription;

void _startListeningToScannedResults() async {
  // listen to onScannedResultsAvailable stream
  subscription = WiFiScan.instance.onScannedResultsAvailable.listen((result) {
    if (result.hasError){
      switch (error){
      // handle error for values of GetScannedResultErrors
      }  
    } else {
      // update accessPoints
      setState(() => accessPoints = result.value);
    }
  });
}

// 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, GetScannedResultsErrors and Result<ValueType, ErrorType>.

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.

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