file_properties_item_widget.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import "package:flutter/material.dart";
  2. import 'package:path/path.dart' as path;
  3. import "package:photos/models/file.dart";
  4. import "package:photos/models/file_type.dart";
  5. import "package:photos/theme/ente_theme.dart";
  6. import "package:photos/ui/components/info_item_widget.dart";
  7. import "package:photos/utils/date_time_util.dart";
  8. import "package:photos/utils/file_util.dart";
  9. import "package:photos/utils/magic_util.dart";
  10. class FilePropertiesItemWidget extends StatefulWidget {
  11. final File file;
  12. final bool isImage;
  13. final Map<String, dynamic> exifData;
  14. final int currentUserID;
  15. const FilePropertiesItemWidget(
  16. this.file,
  17. this.isImage,
  18. this.exifData,
  19. this.currentUserID, {
  20. super.key,
  21. });
  22. @override
  23. State<FilePropertiesItemWidget> createState() =>
  24. _FilePropertiesItemWidgetState();
  25. }
  26. class _FilePropertiesItemWidgetState extends State<FilePropertiesItemWidget> {
  27. @override
  28. Widget build(BuildContext context) {
  29. return InfoItemWidget(
  30. key: const ValueKey("File properties"),
  31. leadingIcon: widget.isImage
  32. ? Icons.photo_outlined
  33. : Icons.video_camera_back_outlined,
  34. title: path.basenameWithoutExtension(widget.file.displayName) +
  35. path.extension(widget.file.displayName).toUpperCase(),
  36. subtitleSection: _subTitleSection(),
  37. editOnTap: widget.file.uploadedFileID == null ||
  38. widget.file.ownerID != widget.currentUserID
  39. ? null
  40. : () async {
  41. await editFilename(context, widget.file);
  42. setState(() {});
  43. },
  44. );
  45. }
  46. Future<List<Widget>> _subTitleSection() async {
  47. final bool showDimension = widget.exifData["resolution"] != null &&
  48. widget.exifData["megaPixels"] != null;
  49. final subSectionWidgets = <Widget>[];
  50. if (showDimension) {
  51. subSectionWidgets.add(
  52. Text(
  53. "${widget.exifData["megaPixels"]}MP "
  54. "${widget.exifData["resolution"]} ",
  55. style: getEnteTextTheme(context).miniMuted,
  56. ),
  57. );
  58. }
  59. int fileSize;
  60. if (widget.file.fileSize != null) {
  61. fileSize = widget.file.fileSize!;
  62. } else {
  63. fileSize = await getFile(widget.file).then((f) => f!.length());
  64. }
  65. subSectionWidgets.add(
  66. Text(
  67. (fileSize / (1024 * 1024)).toStringAsFixed(2) + " MB",
  68. style: getEnteTextTheme(context).miniMuted,
  69. ),
  70. );
  71. if ((widget.file.fileType == FileType.video) &&
  72. (widget.file.localID != null || widget.file.duration != 0)) {
  73. if (widget.file.duration != 0) {
  74. subSectionWidgets.add(
  75. Text(
  76. secondsToHHMMSS(widget.file.duration!),
  77. style: getEnteTextTheme(context).miniMuted,
  78. ),
  79. );
  80. } else {
  81. final asset = await widget.file.getAsset;
  82. subSectionWidgets.add(
  83. Text(
  84. asset?.videoDuration.toString().split(".")[0] ?? "",
  85. style: getEnteTextTheme(context).miniMuted,
  86. ),
  87. );
  88. }
  89. }
  90. return Future.value(subSectionWidgets);
  91. }
  92. }