@@ -93,7 +93,7 @@ class ConnectController extends ChangeNotifier {
9393 BleReadiness _readiness;
9494 List <ScanHit > _hits;
9595 DeviceInfo ? _deviceInfo;
96- bool _fetchingInfo = false ;
96+ Object ? _fetchingInfoSessionStamp ;
9797 bool _disposed = false ;
9898
9999 StreamSubscription <BleReadiness >? _readinessSub;
@@ -163,22 +163,38 @@ class ConnectController extends ChangeNotifier {
163163 /// proof the round-trip works — and clears it on `disconnected` .
164164 void _maybeFetchInfo (ConnState s) {
165165 if (s == ConnState .ready || s == ConnState .running) {
166- if (_deviceInfo == null && ! _fetchingInfo) {
167- unawaited (_fetchInfo ());
166+ final Object sessionStamp = connectionSessionStampOf (_manager.connection);
167+ if (_deviceInfo == null &&
168+ ! identical (_fetchingInfoSessionStamp, sessionStamp)) {
169+ _fetchingInfoSessionStamp = sessionStamp;
170+ unawaited (_fetchInfo (sessionStamp));
168171 }
169172 } else if (s == ConnState .disconnected) {
170173 _deviceInfo = null ;
174+ _fetchingInfoSessionStamp = null ;
171175 }
172176 }
173177
174- Future <void > _fetchInfo () async {
175- _fetchingInfo = true ;
178+ Future <void > _fetchInfo (Object sessionStamp) async {
176179 try {
177- _deviceInfo = await _manager.connection.deviceInfo ();
180+ final DeviceInfo info = await _manager.connection.deviceInfo ();
181+ final ConnState current = _manager.connection.state.value;
182+ if (! _disposed &&
183+ identical (
184+ connectionSessionStampOf (_manager.connection),
185+ sessionStamp,
186+ ) &&
187+ (current == ConnState .ready || current == ConnState .running)) {
188+ _deviceInfo = info;
189+ }
178190 } on Object {
179191 // Leave null; any connect error surfaces via lastError/phase instead.
180192 } finally {
181- _fetchingInfo = false ;
193+ // A replacement session may already have started its own fetch. A late
194+ // prior-session completion must not clear that current in-flight stamp.
195+ if (identical (_fetchingInfoSessionStamp, sessionStamp)) {
196+ _fetchingInfoSessionStamp = null ;
197+ }
182198 _safeNotify ();
183199 }
184200 }
@@ -200,7 +216,9 @@ class ConnectController extends ChangeNotifier {
200216}
201217
202218/// The connect controller provider, wired to the root [connectionManagerProvider]
203- /// (ADR-0009). Auto-disposed with the surface; the manager it wraps outlives it.
219+ /// (ADR-0009). Auto-disposed when neither the pre-connection Connect surface nor
220+ /// the connected shell's status pill watches it; the manager it wraps outlives
221+ /// it.
204222final AutoDisposeChangeNotifierProvider <ConnectController >
205223connectControllerProvider =
206224 ChangeNotifierProvider .autoDispose <ConnectController >(
0 commit comments