openDirectoryOrFile method

Future<void> openDirectoryOrFile(
  1. File file
)

Opens a directory containing the provided File.

If directory cannot be opened (for example, on Android or iOS), then opens the File itself.

Implementation

Future<void> openDirectoryOrFile(File file) async {
  if (PlatformUtils.isWeb) {
    // Web doesn't allow that.
    return;
  }

  if (PlatformUtils.isWindows) {
    // `explorer` is always included on Windows.
    await Process.start('explorer', ['/select,', p.normalize(file.path)]);
  } else if (PlatformUtils.isMacOS) {
    // `open` is always included on macOS.
    await Process.start('open', ['-R', p.normalize(file.path)]);
  } else if (PlatformUtils.isLinux) {
    // `xdg-open` seems to be installed by default in a large amount of
    // distros, thus we may rely on it installed on the user's machine.
    await Process.start('xdg-open', [p.normalize(file.parent.path)]);
  } else {
    await OpenFile.open(file.path);
  }
}