Suppress connector state publication after dispose

Fifth review round:

- MeshCoreConnector.dispose() sets _disposed, and _setState(),
  notifyListeners() and markNotifyDirty() no-op afterwards. A teardown
  started before disposal can still be running (the USB native close waits
  out the kernel's closing_wait off the UI isolate), and its tail would
  otherwise call notifyListeners() on a disposed ChangeNotifier.
- _handleSerialData() now only drops callbacks in the teardown states
  (disconnecting/disconnected) instead of everything that is not
  `connected`, so data arriving in the `connecting` window is still
  ingested and buffered by the frame decoder.
This commit is contained in:
Gianluca Boiano committed 2026-09-13 15:42:34 +02:00
1 parent fb7958a52e
commit fa9e9d18cd
2 files changed
+12 -2

No files matched your search

+4 -2
View File
@@ -527,10 +527,12 @@ class UsbSerialService {
}
void _handleSerialData(FlSerialEventArgs event) {
if (_status != UsbSerialStatus.connected) {
if (_status == UsbSerialStatus.disconnecting ||
_status == UsbSerialStatus.disconnected) {
// Teardown already invalidated the native handle; a callback queued
// before that would make readList() throw and publish a spurious
// transport error that triggers another disconnect.
// transport error that triggers another disconnect. Data that arrives
// while still `connecting` is kept — the decoder buffers it.
return;
}
try {