20 lines
596 B
Dart
20 lines
596 B
Dart
import 'dart:io';
|
|
|
|
import 'package:file_selector/file_selector.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
Future<String?> pickPath(String value, {bool executable = false}) async {
|
|
final directory = value.isEmpty ? null : p.dirname(value);
|
|
final selected = await openFile(
|
|
initialDirectory: directory != null && Directory(directory).existsSync()
|
|
? directory
|
|
: null,
|
|
acceptedTypeGroups: executable && Platform.isWindows
|
|
? [
|
|
const XTypeGroup(label: '可执行程序', extensions: ['exe']),
|
|
]
|
|
: [],
|
|
);
|
|
return selected?.path;
|
|
}
|