implemented file thumbnails and enhanced file type icons, added reusable FileLeading widget, and updated search to support previews

This commit is contained in:
2026-05-13 20:05:54 +02:00
parent 092f9b622b
commit d9fcd9f624
6 changed files with 341 additions and 10 deletions
@@ -5,6 +5,7 @@ import '../../../../api/marianumcloud/webdav/queries/list_files/cacheable_file.d
import '../../../../extensions/date_time.dart';
import '../../../../utils/clipboard_helper.dart';
import '../../../../widget/details_bottom_sheet.dart';
import 'file_leading.dart';
/// Shows a modal bottom sheet with technical metadata about a single file or
/// folder: full path, MIME type, size, timestamps, ETag.
@@ -12,10 +13,7 @@ void showFileDetailsSheet(BuildContext context, CacheableFile file) {
showDetailsBottomSheet(
context,
header: ListTile(
leading: Icon(
file.isDirectory ? Icons.folder : Icons.description_outlined,
size: 32,
),
leading: FileLeading(file: file, size: 40),
title: Text(
file.name,
style: const TextStyle(fontWeight: FontWeight.bold),
@@ -16,6 +16,7 @@ import '../../../../widget/details_bottom_sheet.dart';
import '../../../../widget/info_dialog.dart';
import '../../talk/widgets/highlighted_linkify.dart';
import 'file_details_sheet.dart';
import 'file_leading.dart';
class FileElement extends StatefulWidget {
final CacheableFile file;
@@ -372,9 +373,7 @@ class _FileElementState extends State<FileElement> {
@override
Widget build(BuildContext context) => ListTile(
leading: CenteredLeading(
Icon(widget.file.isDirectory ? Icons.folder : Icons.description_outlined),
),
leading: CenteredLeading(FileLeading(file: widget.file)),
title: _title(context),
subtitle: _subtitle(),
trailing: Icon(widget.file.isDirectory ? Icons.arrow_right : null),
@@ -0,0 +1,51 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import '../../../../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
import '../../../../model/account_data.dart';
import '../../../../model/endpoint_data.dart';
import '../data/file_type_icon.dart';
/// Leading slot for a file row: shows the Nextcloud thumbnail when the
/// server can render one (`nc:has-preview`), otherwise a typed file icon.
/// Always reserves the same square so rows stay aligned regardless of
/// whether a preview is present.
class FileLeading extends StatelessWidget {
final CacheableFile file;
/// Edge length of the rendered square. Defaults to the regular row size;
/// use a larger value (e.g. in detail sheets) where appropriate.
final double size;
const FileLeading({required this.file, this.size = 28, super.key});
@override
Widget build(BuildContext context) {
final icon = Icon(iconForFile(file), size: size);
final fileId = file.fileId;
return SizedBox(
width: size,
height: size,
child: (file.isDirectory || file.hasPreview != true || fileId == null)
? Center(child: icon)
: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: CachedNetworkImage(
imageUrl:
'https://${EndpointData().nextcloud().full()}'
'/index.php/core/preview'
'?fileId=$fileId&x=128&y=128&a=0',
httpHeaders: AccountData().authHeaders(),
fit: BoxFit.cover,
fadeInDuration: Duration.zero,
fadeOutDuration: Duration.zero,
errorListener: (_) {},
// Icon doubles as the loading placeholder so the list doesn't
// pop a spinner per row while thumbnails stream in.
placeholder: (_, _) => Center(child: icon),
errorWidget: (_, _, _) => Center(child: icon),
),
),
);
}
}