isPotentialFilePathAsync method

Future<bool> isPotentialFilePathAsync(
  1. String text
)

Asynchronously detects if a pasted text string represents a potential local file path.

First performs a fast lexical check. If that fails, it queries the filesystem asynchronously to verify if the file exists, avoiding blocking the Dart event loop.

Implementation

Future<bool> isPotentialFilePathAsync(String text) async {
  final trimmed = text.trim();
  if (trimmed.isEmpty) return false;

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

  // Verify physical file presence on the provided filesystem asynchronously
  try {
    final entityType = await fileSystem.type(trimmed);
    return entityType != FileSystemEntityType.notFound;
  } catch (_) {
    return false;
  }
}