merge new features

This commit is contained in:
2026-05-27 19:19:11 +08:00
parent 886046a72b
commit 98af110531
37 changed files with 6405 additions and 993 deletions
@@ -1,11 +1,17 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lucide_icons/lucide_icons.dart';
import 'package:provider/provider.dart';
import '../../../core/utils/date_utils.dart' as date_utils;
import '../../../core/utils/file_type_utils.dart';
import '../../../data/models/file_model.dart';
import '../../../router/app_router.dart';
import '../../../services/file_service.dart';
import '../../providers/file_manager_provider.dart';
import '../../widgets/file_info_dialog.dart';
import '../../widgets/file_operation_dialogs.dart';
import '../../widgets/selection_toolbar.dart';
import '../../widgets/thumbnail_image.dart';
import '../../widgets/toast_helper.dart';
@@ -46,23 +52,34 @@ class CategoryFilesPageArgs {
class CategoryFilesPage extends StatefulWidget {
final CategoryFilesPageArgs args;
const CategoryFilesPage({super.key, required this.args});
const CategoryFilesPage({
super.key,
required this.args,
});
@override
State<CategoryFilesPage> createState() => _CategoryFilesPageState();
}
class _CategoryFilesPageState extends State<CategoryFilesPage> {
class _CategoryFilesPageState extends State<CategoryFilesPage>
with TickerProviderStateMixin {
final _fileService = FileService();
final _scrollController = ScrollController();
final List<FileModel> _files = [];
final Set<String> _selectedFilePaths = <String>{};
String? _nextPageToken;
String? _contextHint;
bool _isLoading = true;
bool _isLoadingMore = false;
String? _errorMessage;
bool get _hasSelection => _selectedFilePaths.isNotEmpty;
List<FileModel> get _selectedFiles => _files
.where((file) => _selectedFilePaths.contains(file.path))
.toList(growable: false);
@override
void initState() {
super.initState();
@@ -74,6 +91,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
void didUpdateWidget(covariant CategoryFilesPage oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.args.category != widget.args.category) {
_clearSelection();
_loadFiles(refresh: true);
}
}
@@ -102,6 +120,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
_nextPageToken = null;
_contextHint = null;
_files.clear();
_selectedFilePaths.clear();
});
} else {
setState(() {
@@ -118,8 +137,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
);
final filesData = response['files'] as List<dynamic>? ?? const [];
final pagination =
response['pagination'] as Map<String, dynamic>? ?? const {};
final pagination = response['pagination'] as Map<String, dynamic>? ?? const {};
final newFiles = filesData
.map((item) => FileModel.fromJson(item as Map<String, dynamic>))
.where((file) => file.isFile)
@@ -134,9 +152,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
..addAll(newFiles);
} else {
final existingIds = _files.map((e) => e.id).toSet();
_files.addAll(
newFiles.where((file) => !existingIds.contains(file.id)),
);
_files.addAll(newFiles.where((file) => !existingIds.contains(file.id)));
}
_nextPageToken = pagination['next_token'] as String?;
@@ -156,22 +172,149 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
Future<void> _refresh() => _loadFiles(refresh: true);
void _toggleSelection(FileModel file) {
HapticFeedback.selectionClick();
setState(() {
if (_selectedFilePaths.contains(file.path)) {
_selectedFilePaths.remove(file.path);
} else {
_selectedFilePaths.add(file.path);
}
});
}
void _clearSelection() {
if (_selectedFilePaths.isEmpty) return;
setState(_selectedFilePaths.clear);
}
void _selectAllVisible() {
setState(() {
_selectedFilePaths
..clear()
..addAll(_files.map((file) => file.path));
});
}
@override
Widget build(BuildContext context) {
return PopScope(
canPop: !_hasSelection,
onPopInvokedWithResult: (didPop, result) {
if (!didPop && _hasSelection) {
_clearSelection();
}
},
child: Scaffold(
appBar: _buildAppBar(context),
body: RefreshIndicator(
onRefresh: _refresh,
child: _buildBody(context),
),
bottomNavigationBar: _buildSelectionBottomBar(context),
),
);
}
PreferredSizeWidget _buildAppBar(BuildContext context) {
final args = widget.args;
return Scaffold(
appBar: AppBar(
title: Text(args.title),
if (_hasSelection) {
return AppBar(
automaticallyImplyLeading: false,
leading: IconButton(
icon: const Icon(LucideIcons.x),
tooltip: '取消选择',
onPressed: _clearSelection,
),
centerTitle: true,
title: Text('已选中 ${_selectedFilePaths.length} 个文件'),
actions: [
IconButton(
icon: const Icon(LucideIcons.refreshCw),
tooltip: '刷新',
onPressed: _refresh,
TextButton(
onPressed: _selectAllVisible,
child: const Text('全选'),
),
],
);
}
return AppBar(
title: Text(args.title),
actions: [
IconButton(
icon: const Icon(LucideIcons.refreshCw),
tooltip: '刷新',
onPressed: _refresh,
),
],
);
}
Widget _buildSelectionBottomBar(BuildContext context) {
final selected = _selectedFiles;
final singleSelected = selected.length == 1 ? selected.first : null;
return AnimatedSize(
duration: const Duration(milliseconds: 220),
curve: Curves.easeOutCubic,
alignment: Alignment.bottomCenter,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 220),
switchInCurve: Curves.easeOutCubic,
switchOutCurve: Curves.easeInCubic,
layoutBuilder: (currentChild, previousChildren) {
return Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
...previousChildren,
?currentChild,
],
);
},
transitionBuilder: (child, animation) {
final curved = CurvedAnimation(
parent: animation,
curve: Curves.easeOutCubic,
reverseCurve: Curves.easeInCubic,
);
final slide = Tween<Offset>(
begin: const Offset(0, 0.10),
end: Offset.zero,
).animate(curved);
return FadeTransition(
opacity: curved,
child: SlideTransition(position: slide, child: child),
);
},
child: _hasSelection
? SelectionToolbar(
key: const ValueKey('category-selection-toolbar'),
selectionCount: _selectedFilePaths.length,
totalCount: _files.length,
onCancel: _clearSelection,
onSelectAll: _selectAllVisible,
onMore: singleSelected == null
? null
: () => _showSelectionMore(context, singleSelected),
onMove: () => FileOperationDialogs.showBatchMoveDialog(
context,
context.read<FileManagerProvider>(),
_selectedFilePaths.toList(),
false,
),
onCopy: () => FileOperationDialogs.showBatchMoveDialog(
context,
context.read<FileManagerProvider>(),
_selectedFilePaths.toList(),
true,
),
onDelete: () => _deleteSelectedFiles(context, selected),
)
: const SizedBox.shrink(
key: ValueKey('category-selection-toolbar-empty'),
),
),
body: RefreshIndicator(onRefresh: _refresh, child: _buildBody(context)),
);
}
@@ -216,7 +359,11 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
physics: const AlwaysScrollableScrollPhysics(),
children: [
SizedBox(height: MediaQuery.sizeOf(context).height * 0.25),
Icon(widget.args.icon, size: 52, color: widget.args.color),
Icon(
widget.args.icon,
size: 52,
color: widget.args.color,
),
const SizedBox(height: 12),
Center(
child: Text(
@@ -236,7 +383,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
final horizontalPadding = width >= 720 ? 16.0 : 10.0;
final columnWidth =
(width - horizontalPadding * 2 - spacing * (columnCount - 1)) /
columnCount;
columnCount;
final columns = List.generate(columnCount, (_) => <FileModel>[]);
final heights = List.generate(columnCount, (_) => 0.0);
@@ -244,8 +391,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
for (final file in _files) {
final targetIndex = _indexOfMin(heights);
columns[targetIndex].add(file);
heights[targetIndex] +=
_estimatedTileHeight(file, columnWidth) + spacing;
heights[targetIndex] += _estimatedTileHeight(file, columnWidth) + spacing;
}
return ListView(
@@ -255,7 +401,7 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
horizontalPadding,
10,
horizontalPadding,
24,
_hasSelection ? 92 : 24,
),
children: [
_buildSummaryHeader(context),
@@ -271,11 +417,22 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
Padding(
padding: EdgeInsets.only(bottom: spacing),
child: _CategoryFileTile(
key: ValueKey('category-file-${file.id.isNotEmpty ? file.id : file.path}'),
file: file,
contextHint: _contextHint,
category: widget.args.category,
accentColor: widget.args.color,
onTap: () => _openFile(context, file),
isSelected: _selectedFilePaths.contains(file.path),
selectionMode: _hasSelection,
onTap: () {
if (_hasSelection) {
_toggleSelection(file);
} else {
_openFile(context, file);
}
},
onLongPress: () => _toggleSelection(file),
onSelect: () => _toggleSelection(file),
),
),
],
@@ -379,19 +536,147 @@ class _CategoryFilesPageState extends State<CategoryFilesPage> {
} else if (FileTypeUtils.isAudio(file.name)) {
Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: file);
} else if (FileTypeUtils.isMarkdown(file.name)) {
Navigator.of(
context,
).pushNamed(RouteNames.markdownPreview, arguments: file);
Navigator.of(context).pushNamed(RouteNames.markdownPreview, arguments: file);
} else if (FileTypeUtils.isTextCode(file.name)) {
Navigator.of(
context,
).pushNamed(RouteNames.documentPreview, arguments: file);
Navigator.of(context).pushNamed(RouteNames.documentPreview, arguments: file);
} else {
ToastHelper.info(
'暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}',
);
ToastHelper.info('暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}');
}
}
Future<void> _deleteSelectedFiles(
BuildContext context,
List<FileModel> selectedFiles,
) async {
if (selectedFiles.isEmpty) return;
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) => AlertDialog(
title: const Text('删除确认'),
content: Text('确定删除这 ${selectedFiles.length} 个文件吗?'),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('取消'),
),
FilledButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.error,
),
child: const Text('删除'),
),
],
),
);
if (confirmed != true) return;
try {
await _fileService.deleteFiles(
uris: selectedFiles.map((file) => file.path).toList(),
);
if (!mounted) return;
setState(() {
final selectedPaths = selectedFiles.map((file) => file.path).toSet();
_files.removeWhere((file) => selectedPaths.contains(file.path));
_selectedFilePaths.clear();
});
ToastHelper.success('删除成功');
} catch (e) {
if (context.mounted) {
ToastHelper.failure('删除失败: $e');
}
}
}
Future<void> _renameFile(BuildContext context, FileModel file) async {
final controller = TextEditingController(text: file.name);
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) => AlertDialog(
title: const Text('重命名'),
content: TextField(
controller: controller,
decoration: const InputDecoration(
labelText: '新名称',
prefixIcon: Icon(LucideIcons.edit3, size: 20),
),
autofocus: true,
onSubmitted: (_) => Navigator.of(dialogContext).pop(true),
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('取消'),
),
FilledButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('确定'),
),
],
),
);
final newName = controller.text.trim();
if (confirmed != true || newName.isEmpty || newName == file.name) return;
try {
final response = await _fileService.renameFile(
uri: file.path,
newName: newName,
);
if (!mounted) return;
if (response.isEmpty) {
await _refresh();
} else {
final updatedFile = FileModel.fromJson(response);
setState(() {
final index = _files.indexWhere((item) => item.path == file.path);
if (index != -1) _files[index] = updatedFile;
_selectedFilePaths
..remove(file.path)
..add(updatedFile.path);
});
}
ToastHelper.success('重命名成功');
} catch (e) {
if (context.mounted) {
ToastHelper.failure('重命名失败: $e');
}
}
}
void _showSelectionMore(BuildContext context, FileModel file) {
showModalBottomSheet<void>(
context: context,
builder: (sheetContext) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.edit),
title: const Text('重命名'),
onTap: () {
Navigator.of(sheetContext).pop();
_renameFile(context, file);
},
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('查看详情'),
onTap: () {
Navigator.of(sheetContext).pop();
FileInfoPanel.showAsBottomSheet(context, file);
},
),
],
),
),
);
}
}
class _CategoryFileTile extends StatelessWidget {
@@ -399,14 +684,23 @@ class _CategoryFileTile extends StatelessWidget {
final String? contextHint;
final String category;
final Color accentColor;
final bool isSelected;
final bool selectionMode;
final VoidCallback onTap;
final VoidCallback onLongPress;
final VoidCallback onSelect;
const _CategoryFileTile({
super.key,
required this.file,
required this.contextHint,
required this.category,
required this.accentColor,
required this.isSelected,
required this.selectionMode,
required this.onTap,
required this.onLongPress,
required this.onSelect,
});
@override
@@ -419,73 +713,128 @@ class _CategoryFileTile extends StatelessWidget {
final ext = FileTypeUtils.getExtension(file.name);
final isPsd = ext == 'psd' || ext == 'psb';
return Material(
color: theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(14),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: onTap,
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: theme.dividerColor.withValues(alpha: 0.12),
final borderColor = isSelected
? theme.colorScheme.primary
: theme.dividerColor.withValues(alpha: 0.12);
final showSelectionCircle = selectionMode || isSelected;
return RepaintBoundary(
child: AnimatedScale(
duration: const Duration(milliseconds: 150),
curve: Curves.easeOutCubic,
scale: isSelected ? 0.985 : 1.0,
child: Material(
color: theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(14),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: onTap,
onLongPress: onLongPress,
child: Stack(
clipBehavior: Clip.none,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
AspectRatio(
aspectRatio: isMedia || isPsd ? 1 : 1.45,
child: Stack(
fit: StackFit.expand,
children: [
RepaintBoundary(
child: ThumbnailImage(
file: file,
contextHint: contextHint,
borderRadius: 0,
),
),
Positioned(
top: 7,
left: 7,
child: _TypeBadge(
icon: _badgeIcon(),
label: _badgeLabel(ext),
color: accentColor,
compact: isMedia,
),
),
if (category == 'video')
const Center(
child: _PlayOverlay(),
),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 8, 10, 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
file.name,
maxLines: isAudio || isDocument ? 2 : 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 3),
Text(
'${FileTypeUtils.getFileTypeDescription(file.name)} · ${date_utils.DateUtils.formatFileSize(file.size)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.hintColor,
),
),
],
),
),
],
),
Positioned.fill(
child: IgnorePointer(
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
curve: Curves.easeOutCubic,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: borderColor,
width: isSelected ? 2.2 : 1,
),
boxShadow: isSelected
? [
BoxShadow(
color: theme.colorScheme.primary
.withValues(alpha: 0.12),
blurRadius: 10,
spreadRadius: 0.5,
),
]
: const [],
),
),
),
),
Positioned(
top: 7,
right: 7,
child: AnimatedOpacity(
duration: const Duration(milliseconds: 130),
opacity: showSelectionCircle ? 1 : 0,
child: IgnorePointer(
ignoring: !showSelectionCircle,
child: _SelectionCircle(
selected: isSelected,
onTap: onSelect,
),
),
),
),
],
),
borderRadius: BorderRadius.circular(14),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
AspectRatio(
aspectRatio: isMedia || isPsd ? 1 : 1.45,
child: Stack(
fit: StackFit.expand,
children: [
ThumbnailImage(
file: file,
contextHint: contextHint,
borderRadius: 0,
),
Positioned(
top: 7,
left: 7,
child: _TypeBadge(
icon: _badgeIcon(),
label: _badgeLabel(ext),
color: accentColor,
compact: isMedia,
),
),
if (category == 'video')
const Center(child: _PlayOverlay()),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 8, 10, 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
file.name,
maxLines: isAudio || isDocument ? 2 : 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 3),
Text(
'${FileTypeUtils.getFileTypeDescription(file.name)} · ${date_utils.DateUtils.formatFileSize(file.size)}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.hintColor,
),
),
],
),
),
],
),
),
),
@@ -524,6 +873,60 @@ class _CategoryFileTile extends StatelessWidget {
}
}
class _SelectionCircle extends StatelessWidget {
final bool selected;
final VoidCallback? onTap;
const _SelectionCircle({
required this.selected,
this.onTap,
});
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
customBorder: const CircleBorder(),
child: AnimatedContainer(
duration: const Duration(milliseconds: 160),
width: 28,
height: 28,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: selected
? colorScheme.primary
: colorScheme.surface.withValues(alpha: 0.86),
border: Border.all(
color: selected
? colorScheme.primary
: colorScheme.outline.withValues(alpha: 0.42),
width: 1.4,
),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.10),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: selected
? const Icon(
LucideIcons.check,
color: Colors.white,
size: 16,
)
: null,
),
),
);
}
}
class _TypeBadge extends StatelessWidget {
final IconData icon;
final String label;
@@ -545,7 +948,10 @@ class _TypeBadge extends StatelessWidget {
borderRadius: BorderRadius.circular(9),
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: compact ? 6 : 7, vertical: 4),
padding: EdgeInsets.symmetric(
horizontal: compact ? 6 : 7,
vertical: 4,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -580,7 +986,11 @@ class _PlayOverlay extends StatelessWidget {
),
child: const Padding(
padding: EdgeInsets.all(10),
child: Icon(LucideIcons.play, color: Colors.white, size: 22),
child: Icon(
LucideIcons.play,
color: Colors.white,
size: 22,
),
),
);
}
+136 -216
View File
@@ -56,10 +56,7 @@ class _FilesPageState extends State<FilesPage> {
Future.delayed(const Duration(milliseconds: 100), () {
if (mounted) {
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
final screenWidth = MediaQuery.of(context).size.width;
if (screenWidth >= 1000) {
fileManager.setViewType(FileViewType.grid);
@@ -70,10 +67,7 @@ class _FilesPageState extends State<FilesPage> {
fileManager.loadFiles();
_isFirstLoad = false;
}
final downloadManager = Provider.of<DownloadManagerProvider>(
context,
listen: false,
);
final downloadManager = Provider.of<DownloadManagerProvider>(context, listen: false);
downloadManager.initialize();
}
});
@@ -81,13 +75,8 @@ class _FilesPageState extends State<FilesPage> {
// 上传完成 → 自动刷新当前目录文件列表
UploadService.instance.onUploadCompleted = (targetPath, fileName) {
if (!mounted) return;
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
final normalizedCurrent = FileUtils.toCloudreveUri(
fileManager.currentPath,
);
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
final normalizedCurrent = FileUtils.toCloudreveUri(fileManager.currentPath);
if (targetPath == normalizedCurrent) {
final fileUri = targetPath.endsWith('/')
? '$targetPath$fileName'
@@ -112,6 +101,38 @@ class _FilesPageState extends State<FilesPage> {
});
}
void _showSelectionMore(
FileModel file,
FileManagerProvider fileManager,
) {
showModalBottomSheet<void>(
context: context,
builder: (sheetContext) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.edit),
title: const Text('重命名'),
onTap: () {
Navigator.of(sheetContext).pop();
FileOperationDialogs.showRenameDialog(context, fileManager, file);
},
),
ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('查看详情'),
onTap: () {
Navigator.of(sheetContext).pop();
_showFileInfo(file);
},
),
],
),
),
);
}
// ---- FAB 显隐控制 ----
void _hideFab() {
@@ -188,14 +209,22 @@ class _FilesPageState extends State<FilesPage> {
);
}
/// 循环解码路径段,处理多重 URL 编码(如 %25E4%25B8%25AD → 中文)
String _decodePathSegment(String segment) {
return FileUtils.safeDecodePathSegment(segment);
var decoded = segment;
for (var i = 0; i < 5; i++) {
try {
final next = Uri.decodeComponent(decoded);
if (next == decoded) break;
decoded = next;
} catch (_) {
break;
}
}
return decoded;
}
Widget _buildDesktopBreadcrumb(
BuildContext context,
FileManagerProvider fileManager,
) {
Widget _buildDesktopBreadcrumb(BuildContext context, FileManagerProvider fileManager) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final pathParts = fileManager.currentPath.split('/');
@@ -205,9 +234,7 @@ class _FilesPageState extends State<FilesPage> {
mainAxisSize: MainAxisSize.min,
children: [
InkWell(
onTap: () => fileManager.currentPath != '/'
? fileManager.enterFolder('/')
: null,
onTap: () => fileManager.currentPath != '/' ? fileManager.enterFolder('/') : null,
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
@@ -217,18 +244,12 @@ class _FilesPageState extends State<FilesPage> {
for (int i = 0; i < pathParts.length; i++) ...[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Icon(
LucideIcons.chevronRight,
size: 14,
color: theme.hintColor.withValues(alpha: 0.5),
),
child: Icon(LucideIcons.chevronRight, size: 14, color: theme.hintColor.withValues(alpha: 0.5)),
),
InkWell(
onTap: () {
final targetPath = '/${pathParts.sublist(0, i + 1).join('/')}';
if (targetPath != fileManager.currentPath) {
fileManager.enterFolder(targetPath);
}
if (targetPath != fileManager.currentPath) fileManager.enterFolder(targetPath);
},
borderRadius: BorderRadius.circular(6),
child: Padding(
@@ -236,12 +257,8 @@ class _FilesPageState extends State<FilesPage> {
child: Text(
_decodePathSegment(pathParts[i]),
style: TextStyle(
color: i == pathParts.length - 1
? colorScheme.onSurface
: colorScheme.primary,
fontWeight: i == pathParts.length - 1
? FontWeight.w600
: FontWeight.normal,
color: i == pathParts.length - 1 ? colorScheme.onSurface : colorScheme.primary,
fontWeight: i == pathParts.length - 1 ? FontWeight.w600 : FontWeight.normal,
),
),
),
@@ -251,10 +268,7 @@ class _FilesPageState extends State<FilesPage> {
);
}
Widget _buildMobileBreadcrumb(
BuildContext context,
FileManagerProvider fileManager,
) {
Widget _buildMobileBreadcrumb(BuildContext context, FileManagerProvider fileManager) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final pathParts = fileManager.currentPath.split('/');
@@ -263,6 +277,7 @@ class _FilesPageState extends State<FilesPage> {
return SizedBox(
height: 40,
child: ListView(
key: const PageStorageKey('mobile_breadcrumb'),
scrollDirection: Axis.horizontal,
children: [
_buildBreadcrumbChip(
@@ -270,18 +285,12 @@ class _FilesPageState extends State<FilesPage> {
label: '文件',
icon: LucideIcons.home,
color: colorScheme.primary,
onTap: () => fileManager.currentPath != '/'
? fileManager.enterFolder('/')
: null,
onTap: () => fileManager.currentPath != '/' ? fileManager.enterFolder('/') : null,
),
for (int i = 0; i < pathParts.length; i++) ...[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Icon(
LucideIcons.chevronRight,
size: 14,
color: theme.hintColor.withValues(alpha: 0.5),
),
child: Icon(LucideIcons.chevronRight, size: 14, color: theme.hintColor.withValues(alpha: 0.5)),
),
_buildBreadcrumbChip(
context,
@@ -291,9 +300,7 @@ class _FilesPageState extends State<FilesPage> {
isLast: i == pathParts.length - 1,
onTap: () {
final targetPath = '/${pathParts.sublist(0, i + 1).join('/')}';
if (targetPath != fileManager.currentPath) {
fileManager.enterFolder(targetPath);
}
if (targetPath != fileManager.currentPath) fileManager.enterFolder(targetPath);
},
),
],
@@ -317,9 +324,7 @@ class _FilesPageState extends State<FilesPage> {
height: 28,
padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: isLast
? color.withValues(alpha: 0.15)
: color.withValues(alpha: 0.06),
color: isLast ? color.withValues(alpha: 0.15) : color.withValues(alpha: 0.06),
borderRadius: BorderRadius.circular(14),
),
child: Row(
@@ -353,9 +358,7 @@ class _FilesPageState extends State<FilesPage> {
Consumer<FileManagerProvider>(
builder: (context, fileManager, child) {
return IconButton(
icon: Icon(
fileManager.isLoading ? Icons.hourglass_empty : Icons.refresh,
),
icon: Icon(fileManager.isLoading ? Icons.hourglass_empty : Icons.refresh),
onPressed: () => fileManager.refreshFiles(),
tooltip: '刷新',
);
@@ -375,19 +378,14 @@ class _FilesPageState extends State<FilesPage> {
: FileViewType.list,
);
},
tooltip: fileManager.viewType == FileViewType.list
? '网格视图'
: '列表视图',
tooltip: fileManager.viewType == FileViewType.list ? '网格视图' : '列表视图',
);
},
),
IconButton(
icon: const Icon(Icons.add),
onPressed: () {
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
FileOperationDialogs.showCreateDialog(context, fileManager);
},
tooltip: '新建',
@@ -399,8 +397,7 @@ class _FilesPageState extends State<FilesPage> {
),
IconButton(
icon: const Icon(Icons.cloud_download),
onPressed: () =>
Provider.of<NavigationProvider>(context, listen: false).setIndex(2),
onPressed: () => Provider.of<NavigationProvider>(context, listen: false).setIndex(2),
tooltip: '下载',
),
];
@@ -422,9 +419,7 @@ class _FilesPageState extends State<FilesPage> {
: FileViewType.list,
);
},
tooltip: fileManager.viewType == FileViewType.list
? '网格视图'
: '列表视图',
tooltip: fileManager.viewType == FileViewType.list ? '网格视图' : '列表视图',
);
},
),
@@ -476,16 +471,8 @@ class _FilesPageState extends State<FilesPage> {
isDark: isDark,
colorScheme: colorScheme,
onTap: () {
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
_onFabSubAction(
() => FileOperationDialogs.showCreateDialog(
context,
fileManager,
),
);
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
_onFabSubAction(() => FileOperationDialogs.showCreateDialog(context, fileManager));
},
),
_buildFabSubItem(
@@ -495,10 +482,7 @@ class _FilesPageState extends State<FilesPage> {
label: '离线下载',
isDark: isDark,
colorScheme: colorScheme,
onTap: () => _onFabSubAction(
() =>
Navigator.of(context).pushNamed(RouteNames.remoteDownload),
),
onTap: () => _onFabSubAction(() => Navigator.of(context).pushNamed(RouteNames.remoteDownload)),
),
Consumer<FileManagerProvider>(
builder: (context, fileManager, _) {
@@ -584,10 +568,7 @@ class _FilesPageState extends State<FilesPage> {
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 7,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
decoration: BoxDecoration(
color: isDark
? Colors.white.withValues(alpha: 0.12)
@@ -668,8 +649,7 @@ class _FilesPageState extends State<FilesPage> {
final isDesktop = MediaQuery.of(context).size.width >= 1000;
final child = _buildFileList(context);
if (!isDesktop ||
!Platform.isWindows && !Platform.isLinux && !Platform.isMacOS) {
if (!isDesktop || !Platform.isWindows && !Platform.isLinux && !Platform.isMacOS) {
return child;
}
@@ -693,19 +673,13 @@ class _FilesPageState extends State<FilesPage> {
strokeAlign: BorderSide.strokeAlignOutside,
),
borderRadius: BorderRadius.circular(8),
color: Theme.of(
context,
).colorScheme.surface.withValues(alpha: 0.85),
color: Theme.of(context).colorScheme.surface.withValues(alpha: 0.85),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
LucideIcons.upload,
size: 48,
color: Theme.of(context).colorScheme.primary,
),
Icon(LucideIcons.upload, size: 48, color: Theme.of(context).colorScheme.primary),
const SizedBox(height: 12),
Text(
'释放文件以上传到当前目录',
@@ -735,14 +709,8 @@ class _FilesPageState extends State<FilesPage> {
}
if (files.isEmpty) return;
final uploadManager = Provider.of<UploadManagerProvider>(
context,
listen: false,
);
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
final uploadManager = Provider.of<UploadManagerProvider>(context, listen: false);
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
uploadManager.markShouldShowDialog();
uploadManager.startUpload(files, fileManager.currentPath);
ToastHelper.info('已添加 ${files.length} 个文件到上传队列');
@@ -772,19 +740,12 @@ class _FilesPageState extends State<FilesPage> {
);
}
Widget _buildErrorView(
BuildContext context,
FileManagerProvider fileManager,
) {
Widget _buildErrorView(BuildContext context, FileManagerProvider fileManager) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 64,
color: Theme.of(context).colorScheme.error,
),
Icon(Icons.error_outline, size: 64, color: Theme.of(context).colorScheme.error),
const SizedBox(height: 16),
Text(
fileManager.errorMessage!,
@@ -832,12 +793,13 @@ class _FilesPageState extends State<FilesPage> {
child: NotificationListener<ScrollNotification>(
onNotification: _onScrollNotification,
child: ListView.builder(
key: PageStorageKey('files_list_${fileManager.currentPath}'),
cacheExtent: 900,
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
itemCount: fileManager.files.length,
itemBuilder: (context, index) {
final file = fileManager.files[index];
final isSelected = fileManager.selectedFiles.contains(
file.path,
);
final isSelected = fileManager.selectedFiles.contains(file.path);
return FileListItem(
key: ValueKey('file_${file.id}'),
@@ -859,37 +821,14 @@ class _FilesPageState extends State<FilesPage> {
}
},
onSelect: () => fileManager.toggleSelection(file.path),
onDownload: !file.isFolder
? () => _downloadFile(context, fileManager, file)
: null,
onOpenInBrowser: !file.isFolder
? () => _openInBrowser(context, file)
: null,
onRename: () => FileOperationDialogs.showRenameDialog(
context,
fileManager,
file,
),
onMove: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
false,
),
onCopy: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
true,
),
onShare: () =>
FileOperationDialogs.showShareDialog(context, file),
onDelete: () =>
FileOperationDialogs.showDeleteSingleConfirmation(
context,
fileManager,
file,
),
onDownload: !file.isFolder ? () => _downloadFile(context, fileManager, file) : null,
onOpenInBrowser: !file.isFolder ? () => _openInBrowser(context, file) : null,
onOpenInCloudreveApp: !file.isFolder ? () => _openInCloudreveApp(context, file) : null,
onRename: () => FileOperationDialogs.showRenameDialog(context, fileManager, file),
onMove: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, false),
onCopy: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, true),
onShare: () => FileOperationDialogs.showShareDialog(context, file),
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(context, fileManager, file),
onInfo: () => _showFileInfo(file),
);
},
@@ -918,8 +857,7 @@ class _FilesPageState extends State<FilesPage> {
crossAxisCount = 5;
}
final itemWidth =
(availableWidth - spacing * (crossAxisCount - 1)) / crossAxisCount;
final itemWidth = (availableWidth - spacing * (crossAxisCount - 1)) / crossAxisCount;
final childAspectRatio = itemWidth / 160;
final showCheckbox = fileManager.hasSelection;
@@ -928,6 +866,9 @@ class _FilesPageState extends State<FilesPage> {
child: NotificationListener<ScrollNotification>(
onNotification: _onScrollNotification,
child: GridView.builder(
key: PageStorageKey('files_grid_${fileManager.currentPath}'),
cacheExtent: 1100,
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
padding: const EdgeInsets.all(8),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
@@ -959,36 +900,14 @@ class _FilesPageState extends State<FilesPage> {
}
},
onSelect: () => fileManager.toggleSelection(file.path),
onDownload: !file.isFolder
? () => _downloadFile(context, fileManager, file)
: null,
onOpenInBrowser: !file.isFolder
? () => _openInBrowser(context, file)
: null,
onRename: () => FileOperationDialogs.showRenameDialog(
context,
fileManager,
file,
),
onMove: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
false,
),
onCopy: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
true,
),
onShare: () =>
FileOperationDialogs.showShareDialog(context, file),
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(
context,
fileManager,
file,
),
onDownload: !file.isFolder ? () => _downloadFile(context, fileManager, file) : null,
onOpenInBrowser: !file.isFolder ? () => _openInBrowser(context, file) : null,
onOpenInCloudreveApp: !file.isFolder ? () => _openInCloudreveApp(context, file) : null,
onRename: () => FileOperationDialogs.showRenameDialog(context, fileManager, file),
onMove: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, false),
onCopy: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, true),
onShare: () => FileOperationDialogs.showShareDialog(context, file),
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(context, fileManager, file),
onInfo: () => _showFileInfo(file),
);
},
@@ -1006,33 +925,34 @@ class _FilesPageState extends State<FilesPage> {
if (fileManager.hasSelection) {
return SelectionToolbar(
selectionCount: fileManager.selectedFiles.length,
totalCount: fileManager.files.length,
onCancel: () => fileManager.clearSelection(),
onRename: fileManager.selectedFiles.length == 1
? () => FileOperationDialogs.showRenameDialog(
context,
fileManager,
fileManager.files.firstWhere(
(f) => f.path == fileManager.selectedFiles.first,
),
)
onSelectAll: () => fileManager.selectAll(),
onMore: fileManager.selectedFiles.length == 1
? () => _showSelectionMore(
fileManager.files.firstWhere(
(f) => f.path == fileManager.selectedFiles.first,
),
fileManager,
)
: null,
onMove: () => FileOperationDialogs.showBatchMoveDialog(
context,
fileManager,
fileManager.selectedFiles,
false,
),
context,
fileManager,
fileManager.selectedFiles,
false,
),
onCopy: () => FileOperationDialogs.showBatchMoveDialog(
context,
fileManager,
fileManager.selectedFiles,
true,
),
context,
fileManager,
fileManager.selectedFiles,
true,
),
onDelete: () => FileOperationDialogs.showDeleteConfirmation(
context,
fileManager,
fileManager.selectedFiles,
),
context,
fileManager,
fileManager.selectedFiles,
),
);
}
@@ -1056,17 +976,11 @@ class _FilesPageState extends State<FilesPage> {
} else if (FileTypeUtils.isAudio(file.name)) {
Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: file);
} else if (FileTypeUtils.isMarkdown(file.name)) {
Navigator.of(
context,
).pushNamed(RouteNames.markdownPreview, arguments: file);
Navigator.of(context).pushNamed(RouteNames.markdownPreview, arguments: file);
} else if (FileTypeUtils.isTextCode(file.name)) {
Navigator.of(
context,
).pushNamed(RouteNames.documentPreview, arguments: file);
Navigator.of(context).pushNamed(RouteNames.documentPreview, arguments: file);
} else {
ToastHelper.info(
'暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}',
);
ToastHelper.info('暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}');
}
}
@@ -1075,10 +989,7 @@ class _FilesPageState extends State<FilesPage> {
FileManagerProvider fileManager,
FileModel file,
) async {
final downloadManager = Provider.of<DownloadManagerProvider>(
context,
listen: false,
);
final downloadManager = Provider.of<DownloadManagerProvider>(context, listen: false);
final task = await downloadManager.addDownloadTask(
fileName: file.name,
fileUri: file.relativePath,
@@ -1124,4 +1035,13 @@ class _FilesPageState extends State<FilesPage> {
}
}
}
void _openInCloudreveApp(BuildContext context, FileModel file) {
Navigator.of(context).pushNamed(
RouteNames.cloudreveFileApp,
arguments: {
'file': file,
},
);
}
}