file_widget.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_live_image.dart';
  7. class FileWidget extends StatelessWidget {
  8. final File 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. if (file.fileType == FileType.livePhoto ||
  26. file.fileType == FileType.image) {
  27. return ZoomableLiveImage(
  28. file,
  29. shouldDisableScroll: shouldDisableScroll,
  30. tagPrefix: tagPrefix,
  31. backgroundDecoration: backgroundDecoration,
  32. );
  33. } else if (file.fileType == FileType.video) {
  34. return VideoWidget(
  35. file,
  36. autoPlay: autoPlay, // Autoplay if it was opened directly
  37. tagPrefix: tagPrefix,
  38. playbackCallback: playbackCallback,
  39. );
  40. } else {
  41. Logger('FileWidget').severe('unsupported file type ${file.fileType}');
  42. return const Icon(Icons.error);
  43. }
  44. }
  45. }