1
This commit is contained in:
1 parent
2379b4476f
commit
8531403c33
21 files changed
+2498
-354
No files matched your search
@@ -1,43 +1,46 @@
|
||||
import 'package:code_editor/models/file_item.dart';
|
||||
import 'package:code_editor/providers/editor_provider.dart';
|
||||
import 'package:code_editor/widgets/file_item_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/file_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class FileTreeWidget extends StatelessWidget {
|
||||
final FileItem? rootFileItem;
|
||||
|
||||
const FileTreeWidget({
|
||||
super.key,
|
||||
required this.rootFileItem
|
||||
});
|
||||
const FileTreeWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final rootPath = context.select<EditorProvider, String?>((p) => p.rootPath);
|
||||
final items = context.select<EditorProvider, List<FileItem>>((p) => p.items);
|
||||
|
||||
final root = rootFileItem;
|
||||
if(root == null) {
|
||||
// 1. 如果用户还没有打开/选择任何根目录
|
||||
if (rootPath == null || rootPath.trim().isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"请点击上方按钮打开文件目录",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final children = root.children;
|
||||
if(children.isEmpty) {
|
||||
// 2. 如果已经选择了根目录,但该目录下没有任何文件或子目录
|
||||
if (items.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"目录为空",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -45,13 +48,12 @@ class FileTreeWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: children.length,
|
||||
key: const PageStorageKey('code_editor_file_tree_list'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
return FileItemWidget(
|
||||
fileItem: children[index],
|
||||
fileItem: items[index],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user