An open-source cross-platform alternative to AirDrop
feat: show thumbnail in progress page
Tien Do Nam7364f06c558b
diff --git a/lib/pages/progress_page.dart b/lib/pages/progress_page.dartindex d21edc8c..854f31ef 100644--- a/lib/pages/progress_page.dart+++ b/lib/pages/progress_page.dart@@ -13,6 +13,7 @@ import 'package:localsend_app/util/file_speed_helper.dart';import 'package:localsend_app/util/platform_check.dart';import 'package:localsend_app/widget/custom_progress_bar.dart';import 'package:localsend_app/widget/dialogs/cancel_session_dialog.dart';+import 'package:localsend_app/widget/file_thumbnail.dart';import 'package:open_filex/open_filex.dart';import 'package:routerino/routerino.dart';import 'package:wakelock/wakelock.dart';@@ -125,9 +126,22 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {// titlereturn Padding(padding: const EdgeInsets.only(bottom: 5),- child: Text(- receiveState != null ? t.progressPage.titleReceiving : t.progressPage.titleSending,- style: Theme.of(context).textTheme.headline6,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ receiveState != null ? t.progressPage.titleReceiving : t.progressPage.titleSending,+ style: Theme.of(context).textTheme.headline6,+ ),+ if (checkPlatformWithFileSystem() && receiveState != null)+ Padding(+ padding: const EdgeInsets.only(bottom: 10),+ child: Text(+ '${t.settingsTab.receive.destination}: ${receiveState.destinationDirectory}',+ style: const TextStyle(color: Colors.grey),+ ),+ ),+ ],),);}@@ -138,6 +152,15 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {final fileStatus = receiveState?.files[file.id]?.status ?? sendState!.files[file.id]!.status;final savedToGallery = receiveState?.files[file.id]?.savedToGallery ?? false;+ final String? filePath;+ if (receiveState != null && fileStatus == FileStatus.finished && !savedToGallery) {+ filePath = receiveState.files[file.id]!.path;+ } else if (sendState != null) {+ filePath = sendState.files[file.id]!.path;+ } else {+ filePath = null;+ }+return Padding(padding: const EdgeInsets.symmetric(vertical: 5),child: InkWell(@@ -145,13 +168,14 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {splashFactory: NoSplash.splashFactory,highlightColor: Colors.transparent,hoverColor: Colors.transparent,- onTap: fileStatus == FileStatus.finished && receiveState != null && !savedToGallery- ? () => OpenFilex.open(receiveState.files[file.id]!.path)- : null,+ onTap: filePath != null && receiveState != null ? () => OpenFilex.open(filePath) : null,child: Row(- crossAxisAlignment: CrossAxisAlignment.start,+ crossAxisAlignment: CrossAxisAlignment.center,children: [- Icon(file.fileType.icon, size: 46),+ FilePathThumbnail(+ path: filePath,+ fileType: file.fileType,+ ),const SizedBox(width: 10),Expanded(child: Column(@@ -238,8 +262,6 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {Text(t.progressPage.total.speed(speed: speedInBytes.asReadableFileSize,)),- if (checkPlatformWithFileSystem() && receiveState != null)- Text('${t.settingsTab.receive.destination}: ${receiveState.destinationDirectory}'),],),),diff --git a/lib/widget/file_thumbnail.dart b/lib/widget/file_thumbnail.dartindex 506807b3..e488c3e8 100644--- a/lib/widget/file_thumbnail.dart+++ b/lib/widget/file_thumbnail.dart@@ -12,21 +12,64 @@ class FileThumbnail extends StatelessWidget {@overrideWidget build(BuildContext context) {- Widget? thumbnail;if (file.asset != null) {- thumbnail = AssetEntityImage(- file.asset!,- isOriginal: false,- thumbnailSize: const ThumbnailSize.square(64),- thumbnailFormat: ThumbnailFormat.jpeg,+ return _FileThumbnail(+ thumbnail: AssetEntityImage(+ file.asset!,+ isOriginal: false,+ thumbnailSize: const ThumbnailSize.square(64),+ thumbnailFormat: ThumbnailFormat.jpeg,+ ),+ icon: file.fileType.icon,+ );+ } else {+ return FilePathThumbnail(+ path: file.path,+ fileType: file.fileType,);- } else if (file.path != null && file.fileType == FileType.image) {+ }+ }+}++class FilePathThumbnail extends StatelessWidget {+ final String? path;+ final FileType fileType;++ const FilePathThumbnail({+ required this.path,+ required this.fileType,+ });++ @override+ Widget build(BuildContext context) {+ final Widget? thumbnail;+ if (path != null && fileType == FileType.image) {thumbnail = Image.file(- File(file.path!),+ File(path!),cacheWidth: 64, // reduce memory with low cached size; do not set cacheHeight because the image must keep its ratio);+ } else {+ thumbnail = null;}+ return _FileThumbnail(+ thumbnail: thumbnail,+ icon: fileType.icon,+ );+ }+}++class _FileThumbnail extends StatelessWidget {+ final Widget? thumbnail;+ final IconData? icon;++ const _FileThumbnail({+ required this.thumbnail,+ required this.icon,+ });++ @override+ Widget build(BuildContext context) {return SizedBox(width: 50,height: 50,@@ -35,7 +78,7 @@ class FileThumbnail extends StatelessWidget {child: ColoredBox(color: Theme.of(context).inputDecorationTheme.fillColor!,child: thumbnail == null- ? Icon(file.fileType.icon, size: 32)+ ? Icon(icon!, size: 32): FittedBox(fit: BoxFit.cover,clipBehavior: Clip.hardEdge,