File list drag and drop

This commit is contained in:
2025-11-15 13:22:05 +08:00
parent f94f80c375
commit 7957e4894a
10 changed files with 94 additions and 17 deletions

View File

@@ -99,9 +99,7 @@ class FileListScreen extends HookConsumerWidget {
completer.future
.then((uploadedFile) {
if (uploadedFile != null) {
// Refresh the file list after successful upload
ref.invalidate(cloudFileListNotifierProvider);
showSnackBar('File uploaded successfully');
}
})
.catchError((error) {

View File

@@ -1,3 +1,4 @@
import 'package:desktop_drop/desktop_drop.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
@@ -5,8 +6,10 @@ import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/file_list_item.dart';
import 'package:island/models/file.dart';
import 'package:island/pods/file_list.dart';
import 'package:island/pods/network.dart';
import 'package:island/services/file_uploader.dart';
import 'package:island/utils/format.dart';
import 'package:island/widgets/alert.dart';
import 'package:island/widgets/content/cloud_files.dart';
@@ -36,6 +39,8 @@ class FileListView extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final dragging = useState(false);
useEffect(() {
if (mode.value == FileListMode.normal) {
final notifier = ref.read(cloudFileListNotifierProvider.notifier);
@@ -291,22 +296,70 @@ class FileListView extends HookConsumerWidget {
),
};
return Column(
children: [
const Gap(8),
_buildPathNavigation(ref, currentPath),
const Gap(8),
Expanded(
child: CustomScrollView(
slivers: [
bodyWidget,
const SliverGap(12),
if (mode.value == FileListMode.normal && currentPath.value == '/')
SliverToBoxAdapter(child: _buildUnindexedFilesEntry(ref)),
],
),
return DropTarget(
onDragDone: (details) async {
dragging.value = false;
// Handle file upload
for (final file in details.files) {
final universalFile = UniversalFile(
data: file,
type: UniversalFileType.file,
displayName: file.name,
);
final completer = FileUploader.createCloudFile(
fileData: universalFile,
ref: ref,
path: currentPath.value,
onProgress: (progress, _) {
// Progress is handled by the upload tasks system
if (progress != null) {
debugPrint('Upload progress: ${(progress * 100).toInt()}%');
}
},
);
completer.future
.then((uploadedFile) {
if (uploadedFile != null) {
ref.invalidate(cloudFileListNotifierProvider);
}
})
.catchError((error) {
showSnackBar('Failed to upload file: $error');
});
}
},
onDragEntered: (details) {
dragging.value = true;
},
onDragExited: (details) {
dragging.value = false;
},
child: Container(
color:
dragging.value
? Theme.of(context).primaryColor.withOpacity(0.1)
: null,
child: Column(
children: [
const Gap(8),
_buildPathNavigation(ref, currentPath),
const Gap(8),
Expanded(
child: CustomScrollView(
slivers: [
bodyWidget,
const SliverGap(12),
if (mode.value == FileListMode.normal &&
currentPath.value == '/')
SliverToBoxAdapter(child: _buildUnindexedFilesEntry(ref)),
],
),
),
],
),
],
),
);
}