flutterFrameworkPathExists function
Returns true when the FlutterFramework path declared in packageSwiftPath
resolves to an existing directory on disk.
Flutter 3.22+ places the FlutterFramework SPM package in the example app's
ephemeral directory. The plugin Package.swift references it via a relative
path (../FlutterFramework). This path is resolved at build time by the
Flutter toolchain, but is not resolvable when opening the plugin project
directly in Xcode without a prior flutter pub get in the example app.
Implementation
bool flutterFrameworkPathExists(String packageSwiftPath) {
final file = File(packageSwiftPath);
if (!file.existsSync()) return false;
final content = file.readAsStringSync();
// Extract the path string from: .package(name: "FlutterFramework", path: "...")
final match = RegExp(
r'\.package\s*\(\s*name\s*:\s*"FlutterFramework"\s*,\s*path\s*:\s*"([^"]+)"\s*\)',
).firstMatch(content);
if (match == null) return false;
final relativePath = match.group(1)!;
final packageDir = File(packageSwiftPath).parent.path;
final resolved = p.normalize(p.join(packageDir, relativePath));
return Directory(resolved).existsSync();
}