diff --git a/ui/flutter/lib/util/file_explorer.dart b/ui/flutter/lib/util/file_explorer.dart index 61f14f24..e0ff2b35 100644 --- a/ui/flutter/lib/util/file_explorer.dart +++ b/ui/flutter/lib/util/file_explorer.dart @@ -2,27 +2,37 @@ import 'dart:io'; class FileExplorer { static Future openAndSelectFile(String filePath) async { - if (!await FileSystemEntity.isDirectory(filePath) && - !await FileSystemEntity.isFile(filePath)) { - return; + if (await FileSystemEntity.isFile(filePath)) { + _openFile(filePath); + } else if (await FileSystemEntity.isDirectory(filePath)) { + _openDirectory(filePath); } - if (await FileSystemEntity.isDirectory(filePath)) { - if (Platform.isWindows) { - Process.run('explorer.exe', [filePath]); - } else if (Platform.isMacOS || Platform.isLinux) { - Process.run('xdg-open', [filePath]); + } + + static Future _openDirectory(String directoryPath) async { + if (Platform.isWindows) { + Process.run('explorer.exe', [directoryPath]); + } else if (Platform.isMacOS) { + Process.run('open', [directoryPath]); + } else if (Platform.isLinux) { + if (await _isUbuntuOrDebian()) { + Process.run('xdg-open', [directoryPath]); + } else if (await _isCentOS()) { + Process.run('nautilus', [directoryPath]); } - } else if (await FileSystemEntity.isFile(filePath)) { - if (Platform.isWindows) { - Process.run('explorer.exe', ['/select,', filePath]); - } else if (Platform.isMacOS) { - Process.run('open', ['-R', filePath]); - } else if (Platform.isLinux) { - if (await _isUbuntuOrDebian()) { - Process.run('xdg-open', [filePath]); - } else if (await _isCentOS()) { - Process.run('nautilus', ['--select', filePath]); - } + } + } + + static Future _openFile(String filePath) async { + if (Platform.isWindows) { + Process.run('explorer.exe', ['/select,', filePath]); + } else if (Platform.isMacOS) { + Process.run('open', ['-R', filePath]); + } else if (Platform.isLinux) { + if (await _isUbuntuOrDebian()) { + Process.run('xdg-open', [filePath]); + } else if (await _isCentOS()) { + Process.run('nautilus', ['--select', filePath]); } } }