file_widget.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'package:flutter/material.dart';
  2. import 'package:logging/logging.dart';
  3. import 'package:photos/models/file/file.dart';
  4. import 'package:photos/models/file/file_type.dart';
  5. import "package:photos/ui/viewer/file/video_widget.dart";
  6. import "package:photos/ui/viewer/file/zoomable_live_image_new.dart";
  7. class FileWidget extends StatelessWidget {
  8. final EnteFile file;
  9. final String? tagPrefix;
  10. final Function(bool)? shouldDisableScroll;
  11. final Function(bool)? playbackCallback;
  12. final BoxDecoration? backgroundDecoration;
  13. final bool? autoPlay;
  14. const FileWidget(
  15. this.file, {
  16. this.autoPlay,
  17. this.shouldDisableScroll,
  18. this.playbackCallback,
  19. this.tagPrefix,
  20. this.backgroundDecoration,
  21. Key? key,
  22. }) : super(key: key);
  23. @override
  24. Widget build(BuildContext context) {
  25. // Specify key to ensure that the widget is rebuilt when the file changes
  26. // Before changing this, ensure that file deletes are handled properly
  27. final String fileKey = "file_${file.generatedID}";
  28. if (file.fileType == FileType.livePhoto ||
  29. file.fileType == FileType.image) {
  30. return ZoomableLiveImageNew(
  31. file,
  32. shouldDisableScroll: shouldDisableScroll,
  33. tagPrefix: tagPrefix,
  34. backgroundDecoration: backgroundDecoration,
  35. key: key ?? ValueKey(fileKey),
  36. );
  37. } else if (file.fileType == FileType.video) {
  38. return VideoWidget(
  39. file,
  40. autoPlay: autoPlay ?? false, // Autoplay if it was opened directly
  41. tagPrefix: tagPrefix,
  42. playbackCallback: playbackCallback,
  43. );
  44. // return VideoWidgetNew(
  45. // file,
  46. // tagPrefix: tagPrefix,
  47. // );
  48. } else {
  49. Logger('FileWidget').severe('unsupported file type ${file.fileType}');
  50. return const Icon(Icons.error);
  51. }
  52. }
  53. }