Reputation:
I'm setting up an IoT device over Bluetooth. To do so, I need to get the Wifi details from my user. For simplicity I would like to get a list of the networks based off of connection levels.
Upvotes: 0
Views: 5764
Reputation: 1
To use the google_mlkit_barcode_scanning plugin for scanning WiFi details, you can follow these steps:
Add the google_mlkit_barcode_scanning plugin to your pubspec.yaml file
dependencies: google_mlkit_barcode_scanning: ^0.8.0
BarcodeScanner barcodeScanner = GoogleMlKit.vision.barcodeScanner();
List<Barcode> barcodes = await barcodeScanner.processImage(inputImage);
for (Barcode barcode in barcodes) {
if (barcode.type == BarcodeType.wifi) {
String ssid = barcode.wifi!.ssid;
String password = barcode.wifi!.password;
String encryptionType = barcode.wifi!.encryptionType;
print('SSID: $ssid');
print('Password: $pass`enter code here`word');
print('Encryption Type: $encryptionType');
}
}
Upvotes: 0
Reputation: 535
If you are looking for connectivity details, then check this out:
import 'package:connectivity/connectivity.dart';
var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
// I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
// I am connected to a wifi network.
}
Here is how you find the current SSID:
try {
wifiBSSID = await _connectivity.getWifiBSSID();
} on PlatformException catch (e) {
print(e.toString());
wifiBSSID = "Failed to get Wifi BSSID";
}
An alternative is the FlutterWifi library, but its features on iOS are greatly limited as of now.
Upvotes: 2