Browse Source

feat(neon_files): add FileDetails constructors

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/556/head
Nikolas Rimikis 1 year ago
parent
commit
4bff5547a1
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 23
      packages/neon/neon_files/lib/models/file_details.dart
  2. 52
      packages/neon/neon_files/lib/widgets/browser_view.dart
  3. 2
      packages/neon/neon_files/lib/widgets/file_list_tile.dart

23
packages/neon/neon_files/lib/models/file_details.dart

@ -13,6 +13,29 @@ class FileDetails {
required this.isFavorite,
});
FileDetails.fromWebDav({
required final WebDavFile file,
required final List<String> path,
}) : path = List.from(path)..add(file.name),
isDirectory = file.isDirectory,
size = file.size,
etag = file.etag,
mimeType = file.mimeType,
lastModified = file.lastModified,
hasPreview = file.hasPreview,
isFavorite = file.favorite;
FileDetails.fromUploadTask({
required final UploadTask task,
}) : path = task.path,
size = task.size,
lastModified = task.lastModified,
isDirectory = false,
etag = null,
mimeType = null,
hasPreview = null,
isFavorite = null;
String get name => path.last;
final List<String> path;

52
packages/neon/neon_files/lib/widgets/browser_view.dart

@ -75,15 +75,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
? const SizedBox()
: FileListTile(
context: context,
details: FileDetails(
path: uploadTask.path,
isDirectory: false,
size: uploadTask.size,
etag: null,
mimeType: null,
lastModified: uploadTask.lastModified,
hasPreview: null,
isFavorite: null,
details: FileDetails.fromUploadTask(
task: uploadTask,
),
uploadProgress: uploadTaskProgressSnapshot.data,
downloadProgress: null,
@ -110,27 +103,26 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
stream: matchingDownloadTasks.isNotEmpty
? matchingDownloadTasks.first.progress
: null,
builder: (final context, final downloadTaskProgressSnapshot) => FileListTile(
context: context,
details: FileDetails(
path: [...widget.bloc.path.value, file.name],
isDirectory: matchingUploadTasks.isEmpty && file.isDirectory,
size: matchingUploadTasks.isNotEmpty
? matchingUploadTasks.first.size
: file.size,
etag: matchingUploadTasks.isNotEmpty ? null : file.etag,
mimeType: matchingUploadTasks.isNotEmpty ? null : file.mimeType,
lastModified: matchingUploadTasks.isNotEmpty
? matchingUploadTasks.first.lastModified
: file.lastModified,
hasPreview: matchingUploadTasks.isNotEmpty ? null : file.hasPreview,
isFavorite: matchingUploadTasks.isNotEmpty ? null : file.favorite,
),
uploadProgress: uploadTaskProgressSnapshot.data,
downloadProgress: downloadTaskProgressSnapshot.data,
enableFileActions: widget.enableFileActions,
onPickFile: widget.onPickFile,
),
builder: (final context, final downloadTaskProgressSnapshot) {
final path = widget.bloc.path.value;
final details = matchingUploadTasks.isEmpty
? FileDetails.fromWebDav(
file: file,
path: path,
)
: FileDetails.fromUploadTask(
task: matchingUploadTasks.first,
);
return FileListTile(
context: context,
details: details,
uploadProgress: uploadTaskProgressSnapshot.data,
downloadProgress: downloadTaskProgressSnapshot.data,
enableFileActions: widget.enableFileActions,
onPickFile: widget.onPickFile,
);
},
),
);
},

2
packages/neon/neon_files/lib/widgets/file_list_tile.dart

@ -84,7 +84,7 @@ class FileListTile extends StatelessWidget {
progress: _progress,
details: details,
),
trailing: _hasProgress && enableFileActions
trailing: !_hasProgress && enableFileActions
? FileActions(details: details)
: const SizedBox.square(
dimension: 48,

Loading…
Cancel
Save