resolveEntrypoint static method

Future<String?> resolveEntrypoint(
  1. JsonRpcClient client,
  2. String isolateId,
  3. String? rootLib, {
  4. Duration? timeout,
})

Resolves the app's root library (e.g. package:shop/main.dart) to the file it was compiled from, or null when the VM service can't say.

Implementation

static Future<String?> resolveEntrypoint(
  JsonRpcClient client,
  String isolateId,
  String? rootLib, {
  Duration? timeout,
}) async {
  if (rootLib == null) return null;
  final Uri? uri = Uri.tryParse(rootLib);
  if (uri == null) return null;
  if (uri.scheme == 'file') return uri.toFilePath();

  try {
    final Object? result = await client.call('lookupResolvedPackageUris', {
      'isolateId': isolateId,
      'uris': [rootLib],
    }, timeout);
    final Object? uris = result is Map ? result['uris'] : null;
    if (uris is List && uris.isNotEmpty && uris.first is String) {
      final Uri? resolved = Uri.tryParse(uris.first as String);
      if (resolved != null && resolved.scheme == 'file') {
        return resolved.toFilePath();
      }
    }
  } on JsonRpcException {
    // Not supported by this VM service (e.g. some web runtimes).
  }
  return null;
}