file_widget.dart 1.7 KB

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