connect method

Future<void> connect(
  1. String wsUri
)

Opens wsUri, selects the main() isolate, and caches its root library.

Throws a StateError when the VM exposes no isolates.

Implementation

Future<void> connect(String wsUri) async {
  await disconnect();
  _vmService = await vmServiceConnectUri(wsUri);
  _wsUri = wsUri;

  final vm = await _vmService!.getVM();
  final isolates = vm.isolates ?? [];
  if (isolates.isEmpty) {
    throw StateError('VM Service connected but exposed no isolates.');
  }

  // Prefer the isolate backed by the app's main() entrypoint.
  final mainIso = isolates.firstWhere(
    (i) => i.name == 'main()',
    orElse: () => isolates.first,
  );
  _isolateId = mainIso.id;

  final isolate = await _vmService!.getIsolate(_isolateId!);
  _rootLibraryId = isolate.rootLib!.id;

  // Flutter Web (dart2js/DDC) does not implement getClassList.
  _supportsClassList = await _detectClassListSupport();
}