file_info_dialog.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import 'package:flutter/material.dart';
  2. import 'package:photo_manager/photo_manager.dart';
  3. import 'package:photos/models/file.dart';
  4. import 'package:photos/models/file_type.dart';
  5. import 'package:photos/services/collections_service.dart';
  6. import 'package:photos/ui/exif_info_dialog.dart';
  7. import 'package:photos/utils/date_time_util.dart';
  8. class FileInfoWidget extends StatelessWidget {
  9. final File file;
  10. final AssetEntity entity;
  11. final int fileSize;
  12. const FileInfoWidget(
  13. this.file,
  14. this.entity,
  15. this.fileSize, {
  16. Key key,
  17. }) : super(key: key);
  18. @override
  19. Widget build(BuildContext context) {
  20. var items = <Widget>[
  21. Row(
  22. children: [
  23. Icon(Icons.calendar_today_outlined),
  24. Padding(padding: EdgeInsets.all(4)),
  25. Text(getFormattedTime(
  26. DateTime.fromMicrosecondsSinceEpoch(file.creationTime))),
  27. ],
  28. ),
  29. Padding(padding: EdgeInsets.all(4)),
  30. Row(
  31. children: [
  32. Icon(Icons.folder_outlined),
  33. Padding(padding: EdgeInsets.all(4)),
  34. Text(file.deviceFolder ??
  35. CollectionsService.instance
  36. .getCollectionByID(file.collectionID)
  37. .name),
  38. ],
  39. ),
  40. Padding(padding: EdgeInsets.all(4)),
  41. ];
  42. if (file.localID != null) {
  43. items.add(
  44. Row(
  45. children: [
  46. Icon(Icons.sd_storage_outlined),
  47. Padding(padding: EdgeInsets.all(4)),
  48. Text((fileSize / (1024 * 1024)).toStringAsFixed(2) + " MB"),
  49. ],
  50. ),
  51. );
  52. items.add(
  53. Padding(padding: EdgeInsets.all(4)),
  54. );
  55. if (file.fileType == FileType.image) {
  56. items.add(
  57. Row(
  58. children: [
  59. Icon(Icons.photo_size_select_actual_outlined),
  60. Padding(padding: EdgeInsets.all(4)),
  61. Text(entity.width.toString() + " x " + entity.height.toString()),
  62. ],
  63. ),
  64. );
  65. } else {
  66. items.add(
  67. Row(
  68. children: [
  69. Icon(Icons.timer_outlined),
  70. Padding(padding: EdgeInsets.all(4)),
  71. Text(entity.videoDuration.toString().split(".")[0]),
  72. ],
  73. ),
  74. );
  75. }
  76. items.add(
  77. Padding(padding: EdgeInsets.all(4)),
  78. );
  79. }
  80. if (file.uploadedFileID != null) {
  81. items.add(
  82. Row(
  83. children: [
  84. Icon(Icons.cloud_upload_outlined),
  85. Padding(padding: EdgeInsets.all(4)),
  86. Text(getFormattedTime(
  87. DateTime.fromMicrosecondsSinceEpoch(file.updationTime))),
  88. ],
  89. ),
  90. );
  91. }
  92. items.add(
  93. Padding(padding: EdgeInsets.all(12)),
  94. );
  95. final List<Widget> actions = [];
  96. if (file.fileType == FileType.image) {
  97. actions.add(
  98. TextButton(
  99. child: Row(
  100. mainAxisAlignment: MainAxisAlignment.spaceAround,
  101. children: [
  102. Icon(
  103. Icons.camera_outlined,
  104. color: Colors.white,
  105. ),
  106. Padding(padding: EdgeInsets.all(4)),
  107. Text(
  108. "view exif",
  109. style: TextStyle(
  110. color: Colors.white.withOpacity(0.8),
  111. ),
  112. ),
  113. ],
  114. ),
  115. onPressed: () {
  116. showDialog(
  117. context: context,
  118. builder: (BuildContext context) {
  119. return ExifInfoDialog(file);
  120. },
  121. barrierColor: Colors.black87,
  122. );
  123. },
  124. ),
  125. );
  126. }
  127. actions.add(
  128. TextButton(
  129. child: Text(
  130. "close",
  131. style: TextStyle(
  132. color: Colors.white.withOpacity(0.8),
  133. ),
  134. ),
  135. onPressed: () {
  136. Navigator.of(context, rootNavigator: true).pop('dialog');
  137. },
  138. ),
  139. );
  140. items.add(
  141. Row(
  142. mainAxisAlignment: file.fileType == FileType.image
  143. ? MainAxisAlignment.spaceBetween
  144. : MainAxisAlignment.end,
  145. children: actions,
  146. ),
  147. );
  148. return AlertDialog(
  149. title: Text(file.title),
  150. content: SingleChildScrollView(
  151. child: ListBody(
  152. children: items,
  153. ),
  154. ),
  155. );
  156. }
  157. }