This commit is contained in:
LZX committed 2026-09-11 13:03:34 +08:00
1 parent 2379b4476f
commit 8531403c33
21 files changed
+2498 -354

No files matched your search

+50 -17
View File
@@ -1,17 +1,50 @@
class FileItem {
final String path;
final String name;
final bool isDirectory;
final List<FileItem> children;
final int depth;
bool isOpen;
FileItem({
required this.path,
required this.name,
this.isDirectory = false,
this.children = const [],
this.depth = 0,
this.isOpen = false
});
}
import 'package:path/path.dart' as p;
class FileItem {
final String fullPath;
final String name;
final String? relativePath;
final bool isDirectory;
List<FileItem> children;
final int depth;
bool isOpen;
FileItem({
required String path,
String? name,
this.relativePath,
this.isDirectory = false,
List<FileItem>? children,
this.depth = 0,
this.isOpen = false,
}) : fullPath = p.normalize(path),
name = name ?? p.basename(path),
children = children ?? [];
/// 完整物理绝对路径别名(完全兼容旧代码)
String get path => fullPath;
/// 文件扩展名(含前导点,如 '.dart'、'.json';文件夹或无扩展名返回 '')
String get extension => isDirectory ? '' : p.extension(fullPath).toLowerCase();
/// 不带扩展名的文件名(如 'main')
String get nameWithoutExtension =>
isDirectory ? name : p.basenameWithoutExtension(fullPath);
/// 优先展示相对路径;若无相对路径则展示纯文件名
String get displayPath => relativePath ?? name;
/// 获取相对于指定 rootPath 的相对路径(优先使用已有相对路径,跨盘或无项目安全回退)
String getRelativePath([String? fromRoot]) {
if (relativePath != null && (fromRoot == null || fromRoot.isEmpty)) {
return relativePath!;
}
final root = fromRoot;
if (root == null || root.trim().isEmpty) return name;
try {
return p.relative(fullPath, from: root);
} catch (_) {
return fullPath;
}
}
}␍