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. 42
      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, 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; String get name => path.last;
final List<String> path; final List<String> path;

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

@ -75,15 +75,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
? const SizedBox() ? const SizedBox()
: FileListTile( : FileListTile(
context: context, context: context,
details: FileDetails( details: FileDetails.fromUploadTask(
path: uploadTask.path, task: uploadTask,
isDirectory: false,
size: uploadTask.size,
etag: null,
mimeType: null,
lastModified: uploadTask.lastModified,
hasPreview: null,
isFavorite: null,
), ),
uploadProgress: uploadTaskProgressSnapshot.data, uploadProgress: uploadTaskProgressSnapshot.data,
downloadProgress: null, downloadProgress: null,
@ -110,27 +103,26 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
stream: matchingDownloadTasks.isNotEmpty stream: matchingDownloadTasks.isNotEmpty
? matchingDownloadTasks.first.progress ? matchingDownloadTasks.first.progress
: null, : null,
builder: (final context, final downloadTaskProgressSnapshot) => FileListTile( 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, context: context,
details: FileDetails( details: details,
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, uploadProgress: uploadTaskProgressSnapshot.data,
downloadProgress: downloadTaskProgressSnapshot.data, downloadProgress: downloadTaskProgressSnapshot.data,
enableFileActions: widget.enableFileActions, enableFileActions: widget.enableFileActions,
onPickFile: widget.onPickFile, onPickFile: widget.onPickFile,
), );
},
), ),
); );
}, },

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

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

Loading…
Cancel
Save