🐛 Update the image site file list, close #204

This commit is contained in:
2025-12-24 23:55:46 +08:00
parent 56ad8f60ea
commit e7e7cc424b

View File

@@ -78,28 +78,24 @@ class FileItem extends HookConsumerWidget {
if (context.mounted) { if (context.mounted) {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: builder: (context) => Scaffold(
(context) => Scaffold( appBar: AppBar(
appBar: AppBar( title: Text(file.relativePath),
title: Text(file.relativePath), backgroundColor: Colors.transparent,
backgroundColor: Colors.transparent, elevation: 0,
elevation: 0, ),
), extendBodyBehindAppBar: true,
extendBodyBehindAppBar: true, backgroundColor: Colors.black,
backgroundColor: Colors.black, body: PhotoView(
body: PhotoView( imageProvider: CachedNetworkImageProvider(
imageProvider: CachedNetworkImageProvider( imageUrl,
imageUrl, headers: token != null
headers: ? {'Authorization': 'AtField $token'}
token != null : null,
? {'Authorization': 'AtField $token'}
: null,
),
heroAttributes: PhotoViewHeroAttributes(
tag: file.relativePath,
),
),
), ),
heroAttributes: PhotoViewHeroAttributes(tag: file.relativePath),
),
),
), ),
); );
} }
@@ -107,7 +103,16 @@ class FileItem extends HookConsumerWidget {
Future<void> _openFile(BuildContext context, WidgetRef ref) async { Future<void> _openFile(BuildContext context, WidgetRef ref) async {
final ext = file.relativePath.split('.').last.toLowerCase(); final ext = file.relativePath.split('.').last.toLowerCase();
final isImage = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'].contains(ext); final isImage = [
'jpg',
'jpeg',
'png',
'gif',
'webp',
'bmp',
'ico',
'svg',
].contains(ext);
if (isImage) { if (isImage) {
await _showImageViewer(context, ref); await _showImageViewer(context, ref);
@@ -182,41 +187,40 @@ class FileItem extends HookConsumerWidget {
: '${(file.size / 1024).toStringAsFixed(1)} KB', : '${(file.size / 1024).toStringAsFixed(1)} KB',
), ),
trailing: PopupMenuButton<String>( trailing: PopupMenuButton<String>(
itemBuilder: itemBuilder: (context) => [
(context) => [ PopupMenuItem(
PopupMenuItem( value: 'download',
value: 'download', child: Row(
child: Row( children: [
children: [ const Icon(Symbols.download),
const Icon(Symbols.download), const Gap(16),
const Gap(16), Text('Download'),
Text('Download'),
],
),
),
if (!file.isDirectory) ...[
PopupMenuItem(
value: 'edit',
child: Row(
children: [
const Icon(Symbols.edit),
const Gap(16),
Text('Open'),
],
),
),
], ],
PopupMenuItem( ),
value: 'delete', ),
child: Row( if (!file.isDirectory) ...[
children: [ PopupMenuItem(
const Icon(Symbols.delete, color: Colors.red), value: 'edit',
const Gap(16), child: Row(
Text('Delete').textColor(Colors.red), children: [
], const Icon(Symbols.edit),
), const Gap(16),
Text('Open'),
],
), ),
], ),
],
PopupMenuItem(
value: 'delete',
child: Row(
children: [
const Icon(Symbols.delete, color: Colors.red),
const Gap(16),
Text('Delete').textColor(Colors.red),
],
),
),
],
onSelected: (value) async { onSelected: (value) async {
switch (value) { switch (value) {
case 'download': case 'download':
@@ -228,23 +232,22 @@ class FileItem extends HookConsumerWidget {
case 'delete': case 'delete':
final confirmed = await showDialog<bool>( final confirmed = await showDialog<bool>(
context: context, context: context,
builder: builder: (context) => AlertDialog(
(context) => AlertDialog( title: const Text('Delete File'),
title: const Text('Delete File'), content: Text(
content: Text( 'Are you sure you want to delete "${file.relativePath}"?',
'Are you sure you want to delete "${file.relativePath}"?', ),
), actions: [
actions: [ TextButton(
TextButton( onPressed: () => Navigator.of(context).pop(false),
onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel'),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
), ),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
),
); );
if (confirmed == true) { if (confirmed == true) {