connect static method
Connects to the VM service of the running isolate, or null.
The whole connect is time-boxed: under some plain flutter test host
contexts Service.getInfo() never completes (no service to answer), so
an unguarded await would hang the scenario instead of degrading. On a
--no-dds --profile device run the service answers immediately and the
timeout never fires.
Implementation
static Future<VmServiceHeap?> connect() async {
try {
final info = await developer.Service
.getInfo()
.timeout(const Duration(seconds: 3));
final uri = info.serverUri;
if (uri == null) return null;
// Same shape integration_test uses in `enableTimeline()`:
// ws://localhost:<port><path>ws
final address = 'ws://localhost:${uri.port}${uri.path}ws';
final service = await vmServiceConnectUri(address);
final vm = await service.getVM();
final isolate = vm.isolates?.firstWhere(
(iso) => iso.isSystemIsolate != true,
);
if (isolate?.id == null) return null;
return VmServiceHeap._(service, isolate!.id!);
} catch (_) {
return null;
}
}