ente/lib/ui/viewer/file/file_widget.dart

63 lines
2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-10-28 05:21:12 +00:00
import 'package:logging/logging.dart';
2023-08-25 04:39:30 +00:00
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
import "package:photos/ui/viewer/file/video_widget.dart";
import "package:photos/ui/viewer/file/video_widget_new.dart";
import "package:photos/ui/viewer/file/zoomable_live_image_new.dart";
import "package:photos/utils/device_info.dart";
class FileWidget extends StatelessWidget {
2023-08-24 16:56:24 +00:00
final EnteFile file;
final String? tagPrefix;
final Function(bool)? shouldDisableScroll;
final Function(bool)? playbackCallback;
final BoxDecoration? backgroundDecoration;
final bool? autoPlay;
const FileWidget(
this.file, {
this.autoPlay,
this.shouldDisableScroll,
this.playbackCallback,
this.tagPrefix,
this.backgroundDecoration,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2023-08-29 22:30:04 +00:00
// Specify key to ensure that the widget is rebuilt when the file changes
// Before changing this, ensure that file deletes are handled properly
final String fileKey = "file_${file.generatedID}";
2023-05-01 10:47:31 +00:00
if (file.fileType == FileType.livePhoto ||
file.fileType == FileType.image) {
return ZoomableLiveImageNew(
file,
shouldDisableScroll: shouldDisableScroll,
tagPrefix: tagPrefix,
backgroundDecoration: backgroundDecoration,
2023-08-29 22:30:04 +00:00
key: key ?? ValueKey(fileKey),
);
} else if (file.fileType == FileType.video) {
if (isCompatibleWithMediaKit()) {
return VideoWidgetNew(
file,
tagPrefix: tagPrefix,
playbackCallback: playbackCallback,
);
} else {
return VideoWidget(
file,
autoPlay: autoPlay ?? false, // Autoplay if it was opened directly
tagPrefix: tagPrefix,
playbackCallback: playbackCallback,
);
}
} else {
Logger('FileWidget').severe('unsupported file type ${file.fileType}');
2022-07-04 06:02:17 +00:00
return const Icon(Icons.error);
}
}
}