initializeSdkForPackage function
Calls all registered Flutter/Dart SDK initializers
The workingDirectory is the directory where the flutter/dart commands are executed.
The enclosing Dart package will be used to determine the Flutter/Dart SDK version.
Implementation
Future<void> initializeSdkForPackage(
Directory? workingDirectory,
) async {
final where = workingDirectory ?? entryWorkingDirectory;
final Directory? packageDir =
where.findParent((dir) => DartPackage.fromDirectory(dir) != null);
final context = SdkInitializerContext(
flutterSdk: flutterSdk,
dartSdk: dartSdk,
packageDir:
packageDir != null ? DartPackage.fromDirectory(packageDir) : null,
workingDirectory: where,
);
for (final initializer in _sdkInitializers) {
try {
await initializer(context);
} catch (e, stack) {
printerr("Error initializing SDKs:\n$e");
printerr(stack);
}
}
}