dbus_wifi 0.0.5
dbus_wifi: ^0.0.5 copied to clipboard
A simple library to connect to Wi-Fi networks using D-Bus on Linux. This library is intended for use with the dbus package in Dart and Flutter.
Examples #
Basic Usage #
void main() async {
final wifi = DbusWifi();
// Check if Wi-Fi device is available
if (await wifi.hasWifiDevice) {
// Search for Wi-Fi networks
final results = await wifi.search(timeout: Duration(seconds: 7));
print('Found ${results.length} networks');
// Connect to a network (e.g., the first one in the list)
if (results.isNotEmpty) {
try {
await wifi.connect(results.first, 'your_password_here');
print('Connected to ${results.first.ssid}');
} catch (e) {
print('Failed to connect: $e');
}
}
// Check connection status
final status = await wifi.getConnectionStatus();
if (status['status'] == ConnectionStatus.connected) {
final network = status['network'];
if (network != null) {
print('Connected to: ${network.ssid}');
}
}
// View saved networks
final savedNetworks = await wifi.getSavedNetworks();
print('Saved networks:');
for (final network in savedNetworks) {
print('- ${network['id']} (${network['uuid']})');
}
// Forget a network (by SSID)
if (savedNetworks.isNotEmpty) {
final networkToForget = savedNetworks.first;
final forgotten = await wifi.forgetNetwork(ssid: networkToForget['id'] as String);
print('Network forgotten: $forgotten');
}
// Disconnect from network
final disconnected = await wifi.disconnect();
print('Disconnected: $disconnected');
}
// Always close the connection when done
await wifi.close();
}
Interactive CLI Example #
The package includes a full-featured CLI application that demonstrates all the functionality. You can run it with:
dart run bin/dbus_wifi.dart
Or install it globally:
dart pub global activate dbus_wifi
dbus-wifi
The CLI application provides a menu-driven interface to:
- Scan for networks
- Connect to a selected network
- Check connection status
- Disconnect from the current network
- View saved networks
- Forget (delete) saved networks
See the bin/dbus_wifi.dart file for the complete implementation.