requireBuildFile function

Directory requireBuildFile(
  1. String directoryPath,
  2. String fileName
)

Checks if a required build file exists within the given directory.

If the file exists, returns a Directory object representing it. Otherwise, throws a FileSystemException.

  • directoryPath: The path to the directory where the file should exist.
  • fileName: The name of the file to check for (e.g., "native_splash_screen.cmake", "NativeSplashScreen.swift").

Implementation

Directory requireBuildFile(String directoryPath, String fileName) {
  // Normalize the directory path first to handle any OS-specific quirks or trailing slashes
  final normalizedDirPath = path.normalize(directoryPath);

  // Construct the full path to the file using the path package for cross-platform compatibility
  final String filePath = path.join(normalizedDirPath, fileName);
  final file = File(filePath);

  if (file.existsSync()) {
    return Directory(normalizedDirPath);
  } else {
    throw FileSystemException();
  }
}