file_info_dialog.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import 'package:exif/exif.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:photo_manager/photo_manager.dart';
  5. import 'package:photos/models/file.dart';
  6. import 'package:photos/models/file_type.dart';
  7. import 'package:photos/services/collections_service.dart';
  8. import 'package:photos/ui/exif_info_dialog.dart';
  9. import 'package:photos/utils/date_time_util.dart';
  10. import 'package:photos/utils/file_util.dart';
  11. class FileInfoWidget extends StatelessWidget {
  12. final File file;
  13. final AssetEntity entity;
  14. const FileInfoWidget(
  15. this.file,
  16. this.entity, {
  17. Key key,
  18. }) : super(key: key);
  19. @override
  20. Widget build(BuildContext context) {
  21. bool isImage = file.fileType == FileType.image;
  22. var items = <Widget>[
  23. Row(
  24. children: [
  25. Icon(
  26. Icons.calendar_today_outlined,
  27. color: Colors.white.withOpacity(0.85),
  28. ),
  29. Padding(padding: EdgeInsets.all(4)),
  30. Text(
  31. getFormattedTime(
  32. DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
  33. ),
  34. style: TextStyle(
  35. color: Colors.white.withOpacity(0.85),
  36. ),
  37. ),
  38. ],
  39. ),
  40. Padding(padding: EdgeInsets.all(6)),
  41. Row(
  42. children: [
  43. Icon(
  44. Icons.folder_outlined,
  45. color: Colors.white.withOpacity(0.85),
  46. ),
  47. Padding(padding: EdgeInsets.all(4)),
  48. Text(
  49. file.deviceFolder ??
  50. CollectionsService.instance
  51. .getCollectionByID(file.collectionID)
  52. .name,
  53. style: TextStyle(
  54. color: Colors.white.withOpacity(0.85),
  55. ),
  56. ),
  57. ],
  58. ),
  59. Padding(padding: EdgeInsets.all(6)),
  60. ];
  61. items.addAll(
  62. [
  63. Row(
  64. children: [
  65. Icon(
  66. Icons.sd_storage_outlined,
  67. color: Colors.white.withOpacity(0.85),
  68. ),
  69. Padding(padding: EdgeInsets.all(4)),
  70. _getFileSize(),
  71. ],
  72. ),
  73. Padding(padding: EdgeInsets.all(6)),
  74. ],
  75. );
  76. if (file.localID != null && !isImage) {
  77. items.addAll(
  78. [
  79. Row(
  80. children: [
  81. Icon(
  82. Icons.timer_outlined,
  83. color: Colors.white.withOpacity(0.85),
  84. ),
  85. Padding(padding: EdgeInsets.all(4)),
  86. Text(
  87. entity.videoDuration.toString().split(".")[0],
  88. style: TextStyle(
  89. color: Colors.white.withOpacity(0.85),
  90. ),
  91. ),
  92. ],
  93. ),
  94. Padding(padding: EdgeInsets.all(6)),
  95. ],
  96. );
  97. }
  98. if (isImage) {
  99. items.add(
  100. FutureBuilder(
  101. future: _getExif(),
  102. builder: (c, snapshot) {
  103. if (snapshot.hasData) {
  104. return _getExifWidgets(snapshot.data);
  105. } else {
  106. return Container();
  107. }
  108. },
  109. ),
  110. );
  111. }
  112. if (file.uploadedFileID != null) {
  113. items.addAll(
  114. [
  115. Row(
  116. children: [
  117. Icon(
  118. Icons.cloud_upload_outlined,
  119. color: Colors.white.withOpacity(0.85),
  120. ),
  121. Padding(padding: EdgeInsets.all(4)),
  122. Text(
  123. getFormattedTime(
  124. DateTime.fromMicrosecondsSinceEpoch(file.updationTime)),
  125. style: TextStyle(
  126. color: Colors.white.withOpacity(0.85),
  127. ),
  128. ),
  129. ],
  130. ),
  131. ],
  132. );
  133. }
  134. items.add(
  135. Padding(padding: EdgeInsets.all(12)),
  136. );
  137. final List<Widget> actions = [];
  138. if (isImage) {
  139. actions.add(
  140. TextButton(
  141. child: Row(
  142. mainAxisAlignment: MainAxisAlignment.spaceAround,
  143. children: [
  144. Icon(
  145. Icons.feed_outlined,
  146. color: Colors.white.withOpacity(0.85),
  147. ),
  148. Padding(padding: EdgeInsets.all(4)),
  149. Text(
  150. "view exif",
  151. style: TextStyle(
  152. color: Colors.white.withOpacity(0.85),
  153. ),
  154. ),
  155. ],
  156. ),
  157. onPressed: () {
  158. showDialog(
  159. context: context,
  160. builder: (BuildContext context) {
  161. return ExifInfoDialog(file);
  162. },
  163. barrierColor: Colors.black87,
  164. );
  165. },
  166. ),
  167. );
  168. }
  169. actions.add(
  170. TextButton(
  171. child: Text(
  172. "close",
  173. style: TextStyle(
  174. color: Colors.white.withOpacity(0.8),
  175. ),
  176. ),
  177. onPressed: () {
  178. Navigator.of(context, rootNavigator: true).pop('dialog');
  179. },
  180. ),
  181. );
  182. items.add(
  183. Row(
  184. mainAxisAlignment:
  185. isImage ? MainAxisAlignment.spaceBetween : MainAxisAlignment.end,
  186. children: actions,
  187. ),
  188. );
  189. return AlertDialog(
  190. title: Text(file.title),
  191. content: SingleChildScrollView(
  192. child: ListBody(
  193. children: items,
  194. ),
  195. ),
  196. );
  197. }
  198. Widget _getExifWidgets(Map<String, IfdTag> exif) {
  199. final focalLength = exif["EXIF FocalLength"] != null
  200. ? (exif["EXIF FocalLength"].values.toList()[0] as Ratio).numerator /
  201. (exif["EXIF FocalLength"].values.toList()[0] as Ratio).denominator
  202. : null;
  203. final fNumber = exif["EXIF FNumber"] != null
  204. ? (exif["EXIF FNumber"].values.toList()[0] as Ratio).numerator /
  205. (exif["EXIF FNumber"].values.toList()[0] as Ratio).denominator
  206. : null;
  207. final List<Widget> children = [];
  208. if (exif["EXIF ExifImageWidth"] != null &&
  209. exif["EXIF ExifImageLength"] != null) {
  210. children.addAll([
  211. Row(
  212. children: [
  213. Icon(
  214. Icons.photo_size_select_actual_outlined,
  215. color: Colors.white.withOpacity(0.85),
  216. ),
  217. Padding(padding: EdgeInsets.all(4)),
  218. Text(
  219. exif["EXIF ExifImageWidth"].toString() +
  220. " x " +
  221. exif["EXIF ExifImageLength"].toString(),
  222. style: TextStyle(
  223. color: Colors.white.withOpacity(0.85),
  224. ),
  225. ),
  226. ],
  227. ),
  228. Padding(padding: EdgeInsets.all(6)),
  229. ]);
  230. } else if (exif["Image ImageWidth"] != null &&
  231. exif["Image ImageLength"] != null) {
  232. children.addAll([
  233. Row(
  234. children: [
  235. Icon(
  236. Icons.photo_size_select_actual_outlined,
  237. color: Colors.white.withOpacity(0.85),
  238. ),
  239. Padding(padding: EdgeInsets.all(4)),
  240. Text(
  241. exif["Image ImageWidth"].toString() +
  242. " x " +
  243. exif["Image ImageLength"].toString(),
  244. style: TextStyle(
  245. color: Colors.white.withOpacity(0.85),
  246. ),
  247. ),
  248. ],
  249. ),
  250. Padding(padding: EdgeInsets.all(6)),
  251. ]);
  252. }
  253. if (exif["Image Make"] != null && exif["Image Model"] != null) {
  254. children.addAll(
  255. [
  256. Row(
  257. children: [
  258. Icon(
  259. Icons.camera_outlined,
  260. color: Colors.white.withOpacity(0.85),
  261. ),
  262. Padding(padding: EdgeInsets.all(4)),
  263. Text(
  264. exif["Image Make"].toString() +
  265. " " +
  266. exif["Image Model"].toString(),
  267. style: TextStyle(
  268. color: Colors.white.withOpacity(0.85),
  269. ),
  270. ),
  271. ],
  272. ),
  273. Padding(padding: EdgeInsets.all(6)),
  274. ],
  275. );
  276. }
  277. if (fNumber != null) {
  278. children.addAll([
  279. Row(
  280. children: [
  281. Icon(
  282. CupertinoIcons.f_cursive,
  283. color: Colors.white.withOpacity(0.85),
  284. ),
  285. Padding(padding: EdgeInsets.all(4)),
  286. Text(
  287. fNumber.toString(),
  288. style: TextStyle(
  289. color: Colors.white.withOpacity(0.85),
  290. ),
  291. ),
  292. ],
  293. ),
  294. Padding(padding: EdgeInsets.all(6)),
  295. ]);
  296. }
  297. if (focalLength != null) {
  298. children.addAll([
  299. Row(
  300. children: [
  301. Icon(
  302. Icons.center_focus_strong_outlined,
  303. color: Colors.white.withOpacity(0.85),
  304. ),
  305. Padding(padding: EdgeInsets.all(4)),
  306. Text(focalLength.toString() + " mm",
  307. style: TextStyle(
  308. color: Colors.white.withOpacity(0.85),
  309. )),
  310. ],
  311. ),
  312. Padding(padding: EdgeInsets.all(6)),
  313. ]);
  314. }
  315. if (exif["EXIF ExposureTime"] != null) {
  316. children.addAll([
  317. Row(
  318. children: [
  319. Icon(
  320. Icons.shutter_speed,
  321. color: Colors.white.withOpacity(0.85),
  322. ),
  323. Padding(padding: EdgeInsets.all(4)),
  324. Text(
  325. exif["EXIF ExposureTime"].toString(),
  326. style: TextStyle(
  327. color: Colors.white.withOpacity(0.85),
  328. ),
  329. ),
  330. ],
  331. ),
  332. Padding(padding: EdgeInsets.all(6)),
  333. ]);
  334. }
  335. return Column(
  336. children: children,
  337. );
  338. }
  339. Widget _getFileSize() {
  340. return FutureBuilder(
  341. future: getFile(file).then((f) => f.lengthSync()),
  342. builder: (context, snapshot) {
  343. if (snapshot.hasData) {
  344. return Text(
  345. (snapshot.data / (1024 * 1024)).toStringAsFixed(2) + " MB",
  346. style: TextStyle(
  347. color: Colors.white.withOpacity(0.85),
  348. ),
  349. );
  350. } else {
  351. return Center(
  352. child: SizedBox.fromSize(
  353. size: Size.square(24),
  354. child: CupertinoActivityIndicator(
  355. radius: 8,
  356. ),
  357. ),
  358. );
  359. }
  360. },
  361. );
  362. }
  363. Future<Map<String, IfdTag>> _getExif() async {
  364. return await readExifFromFile(await getFile(file));
  365. }
  366. }