file_widget.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:flutter/material.dart';
  2. import 'package:logging/logging.dart';
  3. import 'package:photos/models/file.dart';
  4. import 'package:photos/models/file_type.dart';
  5. import 'package:photos/ui/viewer/file/video_widget.dart';
  6. import 'package:photos/ui/viewer/file/zoomable_image.dart';
  7. import 'package:photos/ui/viewer/file/zoomable_live_image.dart';
  8. class FileWidget extends StatelessWidget {
  9. final File file;
  10. final String? tagPrefix;
  11. final Function(bool)? shouldDisableScroll;
  12. final Function(bool)? playbackCallback;
  13. final BoxDecoration? backgroundDecoration;
  14. final bool? autoPlay;
  15. const FileWidget(
  16. this.file, {
  17. this.autoPlay,
  18. this.shouldDisableScroll,
  19. this.playbackCallback,
  20. this.tagPrefix,
  21. this.backgroundDecoration,
  22. Key? key,
  23. }) : super(key: key);
  24. @override
  25. Widget build(BuildContext context) {
  26. if (file.fileType == FileType.image) {
  27. return ZoomableImage(
  28. file,
  29. shouldDisableScroll: shouldDisableScroll,
  30. tagPrefix: tagPrefix,
  31. backgroundDecoration: backgroundDecoration,
  32. );
  33. } else if (file.fileType == FileType.livePhoto) {
  34. return ZoomableLiveImage(
  35. file,
  36. shouldDisableScroll: shouldDisableScroll,
  37. tagPrefix: tagPrefix,
  38. backgroundDecoration: backgroundDecoration,
  39. );
  40. } else if (file.fileType == FileType.video) {
  41. return VideoWidget(
  42. file,
  43. autoPlay: autoPlay, // Autoplay if it was opened directly
  44. tagPrefix: tagPrefix,
  45. playbackCallback: playbackCallback,
  46. );
  47. } else {
  48. Logger('FileWidget').severe('unsupported file type ${file.fileType}');
  49. return const Icon(Icons.error);
  50. }
  51. }
  52. }