refresh method
Implementation
Future<void> refresh() async {
if (!available) {
error = 'The ESP32 bridge is available in desktop builds only.';
_notify();
return;
}
loading = true;
error = null;
_notify();
try {
final List<Esp32Device> found = await _api.listDevices();
devices = found;
if (found.isEmpty) {
selectedPath = null;
} else if (!found.any((Esp32Device d) => d.path == selectedPath)) {
// Prefer the board over an unrelated adapter when both are plugged in.
selectedPath = found
.firstWhere(
(Esp32Device d) => d.espressif,
orElse: () => found.first,
)
.path;
}
} catch (e) {
error = 'Could not list serial ports: $e';
} finally {
loading = false;
_notify();
}
}