ente/lib/ui/viewer/file_details/file_properties_item_widget.dart

100 lines
3 KiB
Dart
Raw Normal View History

import "package:flutter/material.dart";
import 'package:path/path.dart' as path;
import "package:photos/models/file.dart";
import "package:photos/models/file_type.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/components/info_item_widget.dart";
import "package:photos/utils/date_time_util.dart";
import "package:photos/utils/file_util.dart";
import "package:photos/utils/magic_util.dart";
2023-03-13 15:09:51 +00:00
class FilePropertiesItemWidget extends StatefulWidget {
final File file;
final bool isImage;
final Map<String, dynamic> exifData;
final int currentUserID;
2023-03-13 15:09:51 +00:00
const FilePropertiesItemWidget(
this.file,
this.isImage,
this.exifData,
this.currentUserID, {
super.key,
});
@override
2023-03-13 15:09:51 +00:00
State<FilePropertiesItemWidget> createState() =>
_FilePropertiesItemWidgetState();
}
2023-03-13 15:09:51 +00:00
class _FilePropertiesItemWidgetState extends State<FilePropertiesItemWidget> {
@override
Widget build(BuildContext context) {
return InfoItemWidget(
key: const ValueKey("File properties"),
leadingIcon: widget.isImage
? Icons.photo_outlined
: Icons.video_camera_back_outlined,
title: path.basenameWithoutExtension(widget.file.displayName) +
path.extension(widget.file.displayName).toUpperCase(),
2023-03-13 12:17:57 +00:00
subtitleSection: _subTitleSection(),
editOnTap: widget.file.uploadedFileID == null ||
widget.file.ownerID != widget.currentUserID
? null
: () async {
await editFilename(context, widget.file);
setState(() {});
},
);
}
2023-03-13 12:17:57 +00:00
Future<List<Widget>> _subTitleSection() async {
final bool showDimension = widget.exifData["resolution"] != null &&
widget.exifData["megaPixels"] != null;
final subSectionWidgets = <Widget>[];
if (showDimension) {
subSectionWidgets.add(
Text(
"${widget.exifData["megaPixels"]}MP "
"${widget.exifData["resolution"]} ",
style: getEnteTextTheme(context).smallMuted,
),
);
}
int fileSize;
if (widget.file.fileSize != null) {
2023-03-13 12:17:57 +00:00
fileSize = widget.file.fileSize!;
} else {
2023-03-13 12:17:57 +00:00
fileSize = await getFile(widget.file).then((f) => f!.length());
}
2023-03-13 12:17:57 +00:00
subSectionWidgets.add(
Text(
(fileSize / (1024 * 1024)).toStringAsFixed(2) + " MB",
style: getEnteTextTheme(context).smallMuted,
),
);
2023-03-13 12:17:57 +00:00
if ((widget.file.fileType == FileType.video) &&
(widget.file.localID != null || widget.file.duration != 0)) {
if (widget.file.duration != 0) {
subSectionWidgets.add(
Text(
secondsToHHMMSS(widget.file.duration!),
style: getEnteTextTheme(context).smallMuted,
2023-03-13 12:17:57 +00:00
),
);
} else {
final asset = await widget.file.getAsset;
subSectionWidgets.add(
Text(
2023-03-15 06:01:48 +00:00
asset?.videoDuration.toString().split(".")[0] ?? "",
2023-03-13 12:17:57 +00:00
style: getEnteTextTheme(context).smallMuted,
),
);
}
}
return Future.value(subSectionWidgets);
}
}