wifi_scan 0.1.0 wifi_scan: ^0.1.0 copied to clipboard
Flutter plugin to scan for WiFi access points.
| wifi_scan
This plugin allows Flutter apps to trigger WiFi scan and get scanned results.
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 API available | Dummy implementation with sane static 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:
// check if 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:
// check if 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 ofstartScan
API. This returns the latest available scanned results.
For more details, you can read documentation of WiFiScan.getScannedResults
, WiFiAccessPoint
doc_WiFiAccessPoint, WiFiScan.canGetScannedResults
and CanGetScannedResults
.
Get notified when scanned results available #
You can get notified when new scanned results are available, as shown below:
// initialize accessPoints and subscription
List<WiFiAccessPoint> accessPoints = [];
StreamSubscription<List<WiFiAccessPoint>>? subscription;
void _startListeningToScannedResults(){
// check if 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 ofstartScan
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
doc_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.