resolveDartSdkPath function
Resolves the Dart SDK root directory, or null to let the analyzer fall
back to its default (executable-relative) detection.
Resolution order (first match wins):
DART_SDKenvironment variable.DART_HOMEenvironment variable.- Platform.resolvedExecutable — correct under
dart run, where it points at thedartbinary inside the SDK. For compiled binaries this points at the tool itself and is silently skipped (it won't look like an SDK). - The
dartexecutable onPATH(which/where), with symlinks resolved. Handles both the standalone layout (<sdk>/bin/dart) and the Flutter wrapper (<flutter>/bin/dart→<flutter>/bin/cache/dart-sdk). - The
flutterexecutable onPATH→<flutter>/bin/cache/dart-sdk.
Every candidate is validated with looksLikeDartSdk before being returned,
so a stale environment variable or an unrelated dart on PATH never
yields a bogus path. The result is cached for the lifetime of the process.
Implementation
String? resolveDartSdkPath() {
if (_cacheEnabled && _cachedSdkPath != null) return _cachedSdkPath;
final resolved = _resolveUncached();
if (_cacheEnabled) _cachedSdkPath = resolved;
return resolved;
}