isPotentialFilePath method

bool isPotentialFilePath(
  1. String text
)

Detects if a pasted text string represents a potential local file path.

This check is backward compatible and handles both lexical patterns and physical file existence.

Warning

This method performs synchronous filesystem I/O (typeSync). Calling this on the UI thread/rendering loop can block the event loop and cause frame drops. Prefer isLexicallyPotentialFilePath for synchronous UI-thread checks, or isPotentialFilePathAsync for asynchronous verification.

Implementation

bool isPotentialFilePath(String text) {
  final trimmed = text.trim();
  if (trimmed.isEmpty) return false;

  if (isLexicallyPotentialFilePath(trimmed)) {
    return true;
  }

  // Verify physical file presence on the provided filesystem
  try {
    if (fileSystem.typeSync(trimmed) != FileSystemEntityType.notFound) {
      return true;
    }
  } catch (_) {}

  return false;
}