Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions ui/flutter/lib/util/file_explorer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:open_dir/open_dir.dart';
import 'package:path/path.dart' as path;
import 'package:url_launcher/url_launcher_string.dart';

class FileExplorer {
Expand All @@ -16,24 +17,11 @@ class FileExplorer {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open_dir can also be used _openDirectory function.


static Future<void> _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) {
_linuxOpen(filePath);
}
}

static Future<void> _linuxOpen(String filePath) async {
if (await Process.run('which', ['xdg-open'])
.then((value) => value.exitCode == 0)) {
final result = await Process.run('xdg-open', [filePath]);
if (result.exitCode != 0) {
_openWithFileManager(filePath);
}
} else {
_openWithFileManager(filePath);
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
final fileName = path.basename(filePath);
final parentPath = path.dirname(filePath);
await OpenDir()
.openNativeDir(path: parentPath, highlightedFileName: fileName);
}
}

Expand Down
40 changes: 40 additions & 0 deletions ui/flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
open_dir:
dependency: "direct main"
description:
name: open_dir
sha256: a4884b00e5e5795a9b4b3d582ac6a66e9196795ed760dbc3c63b4837c70c5901
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_dir_linux:
dependency: transitive
description:
name: open_dir_linux
sha256: "566cd9e02403971be06af35e1abc8057a4f3f98888c1226042e96a2af333b8bc"
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_dir_macos:
dependency: transitive
description:
name: open_dir_macos
sha256: "51fdc8c3a06c9d571b599b5901045ada23d1440b24c3052c0a66cf3ee4ac901b"
url: "https://pub.dev"
source: hosted
version: "0.0.2"
open_dir_platform_interface:
dependency: transitive
description:
name: open_dir_platform_interface
sha256: ca189abb02d8e3320f9b2493b6d58e3a33f393d5eb4ccbbef02e0bc0fd393872
url: "https://pub.dev"
source: hosted
version: "0.0.2"
open_dir_windows:
dependency: transitive
description:
name: open_dir_windows
sha256: ec48df32ce61adb6f6cede0330d13b0d89714d2ee2df198f32ecd520e3a5d250
url: "https://pub.dev"
source: hosted
version: "0.0.2+1"
open_filex:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions ui/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ dependencies:
win32_registry: ^1.1.5
share_handler: ^0.0.22
crypto: ^3.0.6
open_dir: ^0.0.2+1
install_plugin:
git:
url: https://github.com/hui-z/flutter_install_plugin.git
Expand Down