file_info_dialog.dart 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. import "package:exif/exif.dart";
  2. import "package:flutter/cupertino.dart";
  3. import "package:flutter/material.dart";
  4. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  5. import "package:photos/core/configuration.dart";
  6. import "package:photos/ente_theme_data.dart";
  7. import "package:photos/models/file.dart";
  8. import "package:photos/models/file_type.dart";
  9. import "package:photos/services/collections_service.dart";
  10. import "package:photos/ui/viewer/file/exif_info_dialog.dart";
  11. import "package:photos/utils/date_time_util.dart";
  12. import "package:photos/utils/exif_util.dart";
  13. import "package:photos/utils/file_util.dart";
  14. import "package:photos/utils/magic_util.dart";
  15. import "package:photos/utils/toast_util.dart";
  16. class FileInfoWidget extends StatefulWidget {
  17. final File file;
  18. const FileInfoWidget(
  19. this.file, {
  20. Key key,
  21. }) : super(key: key);
  22. @override
  23. State<FileInfoWidget> createState() => _FileInfoWidgetState();
  24. }
  25. class _FileInfoWidgetState extends State<FileInfoWidget> {
  26. Map<String, IfdTag> _exif;
  27. final Map<String, dynamic> _exifData = {
  28. "focalLength": null,
  29. "fNumber": null,
  30. "resolution": null,
  31. "takenOnDevice": null,
  32. "exposureTime": null,
  33. "ISO": null,
  34. "megaPixels": null
  35. };
  36. bool _isImage = false;
  37. Color infoColor;
  38. @override
  39. void initState() {
  40. debugPrint('file_info_dialog initState');
  41. _isImage = widget.file.fileType == FileType.image ||
  42. widget.file.fileType == FileType.livePhoto;
  43. if (_isImage) {
  44. getExif(widget.file).then((exif) {
  45. setState(() {
  46. _exif = exif;
  47. });
  48. });
  49. }
  50. super.initState();
  51. }
  52. @override
  53. Widget build(BuildContext context) {
  54. final file = widget.file;
  55. final dateTime = DateTime.fromMicrosecondsSinceEpoch(file.creationTime);
  56. final dateTimeForUpdationTime =
  57. DateTime.fromMicrosecondsSinceEpoch(file.updationTime);
  58. infoColor =
  59. Theme.of(context).colorScheme.onSurface.withOpacity(0.85); //remove
  60. if (_isImage && _exif != null) {
  61. _generateExifForDetails(_exif);
  62. }
  63. final bool showExifListTile = _exifData["focalLength"] != null ||
  64. _exifData["fNumber"] != null ||
  65. _exifData["takenOnDevice"] != null ||
  66. _exifData["exposureTime"] != null ||
  67. _exifData["ISO"] != null;
  68. var listTiles = <Widget>[
  69. ListTile(
  70. leading: const Padding(
  71. padding: EdgeInsets.only(top: 8, left: 6),
  72. child: Icon(Icons.calendar_today_rounded),
  73. ),
  74. title: Text(
  75. getFullDate(
  76. DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
  77. ),
  78. ),
  79. subtitle: Text(
  80. getTimeIn12hrFormat(dateTime) + " " + dateTime.timeZoneName,
  81. style: Theme.of(context).textTheme.bodyText2.copyWith(
  82. color: Theme.of(context)
  83. .colorScheme
  84. .defaultTextColor
  85. .withOpacity(0.5),
  86. ),
  87. ),
  88. trailing: (widget.file.ownerID == null ||
  89. widget.file.ownerID ==
  90. Configuration.instance.getUserID()) &&
  91. widget.file.uploadedFileID != null
  92. ? IconButton(
  93. onPressed: () {
  94. _showDateTimePicker(widget.file);
  95. },
  96. icon: const Icon(Icons.edit),
  97. )
  98. : const SizedBox.shrink(),
  99. ),
  100. const DividerWithPadding(),
  101. ListTile(
  102. leading: _isImage
  103. ? const Padding(
  104. padding: EdgeInsets.only(top: 8, left: 6),
  105. child: Icon(
  106. Icons.image,
  107. ),
  108. )
  109. : const Padding(
  110. padding: EdgeInsets.only(top: 8, left: 6),
  111. child: Icon(
  112. Icons.video_camera_back,
  113. size: 27,
  114. ),
  115. ),
  116. title: Text(
  117. file.getDisplayName(),
  118. ),
  119. subtitle: Row(
  120. children: [
  121. Padding(
  122. padding: const EdgeInsets.only(right: 10),
  123. child: _getFileSize(),
  124. ),
  125. !_isImage ? _getVideoDuration() : const SizedBox.shrink(),
  126. ],
  127. ),
  128. trailing: file.uploadedFileID == null ||
  129. file.ownerID != Configuration.instance.getUserID()
  130. ? const SizedBox.shrink()
  131. : IconButton(
  132. onPressed: () async {
  133. await editFilename(context, file);
  134. setState(() {});
  135. },
  136. icon: const Icon(Icons.edit),
  137. ),
  138. ),
  139. const DividerWithPadding(),
  140. showExifListTile
  141. ? ListTile(
  142. leading: const Padding(
  143. padding: EdgeInsets.only(left: 6),
  144. child: Icon(Icons.camera_rounded),
  145. ),
  146. title: Text(_exifData["takenOnDevice"] ?? "--"),
  147. subtitle: Row(
  148. children: [
  149. _exifData["fNumber"] != null
  150. ? Padding(
  151. padding: const EdgeInsets.only(right: 10),
  152. child: Text('ƒ/' + _exifData["fNumber"].toString()),
  153. )
  154. : const SizedBox.shrink(),
  155. _exifData["exposureTime"] != null
  156. ? Padding(
  157. padding: const EdgeInsets.only(right: 10),
  158. child: Text(_exifData["exposureTime"]),
  159. )
  160. : const SizedBox.shrink(),
  161. _exifData["focalLength"] != null
  162. ? Padding(
  163. padding: const EdgeInsets.only(right: 10),
  164. child:
  165. Text(_exifData["focalLength"].toString() + "mm"),
  166. )
  167. : const SizedBox.shrink(),
  168. _exifData["ISO"] != null
  169. ? Padding(
  170. padding: const EdgeInsets.only(right: 10),
  171. child: Text("ISO" + _exifData["ISO"].toString()),
  172. )
  173. : const SizedBox.shrink(),
  174. ],
  175. ),
  176. )
  177. : const SizedBox.shrink(),
  178. showExifListTile ? const DividerWithPadding() : const SizedBox.shrink(),
  179. ListTile(
  180. leading: const Padding(
  181. padding: EdgeInsets.only(left: 6),
  182. child: Icon(Icons.folder_outlined),
  183. ),
  184. title: Text(
  185. file.deviceFolder ??
  186. CollectionsService.instance
  187. .getCollectionByID(file.collectionID)
  188. .name,
  189. ),
  190. ),
  191. const DividerWithPadding(),
  192. (file.uploadedFileID != null && file.updationTime != null)
  193. ? ListTile(
  194. leading: const Padding(
  195. padding: EdgeInsets.only(top: 8, left: 6),
  196. child: Icon(Icons.cloud_upload_outlined),
  197. ),
  198. title: Text(
  199. getFullDate(
  200. DateTime.fromMicrosecondsSinceEpoch(file.updationTime),
  201. ),
  202. ),
  203. subtitle: Text(
  204. getTimeIn12hrFormat(dateTimeForUpdationTime) +
  205. " " +
  206. dateTimeForUpdationTime.timeZoneName,
  207. style: Theme.of(context).textTheme.bodyText2.copyWith(
  208. color: Theme.of(context)
  209. .colorScheme
  210. .defaultTextColor
  211. .withOpacity(0.5)),
  212. ),
  213. )
  214. : const SizedBox.shrink(),
  215. _isImage
  216. ? Padding(
  217. padding: const EdgeInsets.fromLTRB(0, 24, 0, 16),
  218. child: SafeArea(
  219. child: RawExifButton(_exif, widget.file),
  220. ),
  221. )
  222. : const SizedBox(
  223. height: 12,
  224. )
  225. ];
  226. var items = <Widget>[
  227. //remove
  228. Row(
  229. children: [
  230. Icon(Icons.calendar_today_outlined, color: infoColor),
  231. const SizedBox(height: 8),
  232. Text(
  233. getFormattedTime(
  234. DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
  235. ),
  236. style: TextStyle(color: infoColor),
  237. ),
  238. ],
  239. ),
  240. const SizedBox(height: 12),
  241. Row(
  242. children: [
  243. Icon(Icons.folder_outlined, color: infoColor),
  244. const Padding(padding: EdgeInsets.all(4)),
  245. Text(
  246. file.deviceFolder ??
  247. CollectionsService.instance
  248. .getCollectionByID(file.collectionID)
  249. .name,
  250. style: TextStyle(color: infoColor),
  251. ),
  252. ],
  253. ),
  254. const SizedBox(height: 12),
  255. ];
  256. items.addAll(
  257. [
  258. Row(
  259. children: [
  260. Icon(Icons.sd_storage_outlined, color: infoColor),
  261. const Padding(padding: EdgeInsets.all(4)),
  262. _getFileSize(),
  263. ],
  264. ),
  265. const SizedBox(height: 12),
  266. ],
  267. );
  268. if (file.localID != null && !_isImage) {
  269. //remove
  270. items.addAll(
  271. [
  272. Row(
  273. children: [
  274. Icon(Icons.timer_outlined, color: infoColor),
  275. const Padding(padding: EdgeInsets.all(4)),
  276. FutureBuilder(
  277. future: file.getAsset(),
  278. builder: (context, snapshot) {
  279. if (snapshot.hasData) {
  280. return Text(
  281. snapshot.data.videoDuration.toString().split(".")[0],
  282. style: TextStyle(color: infoColor),
  283. );
  284. } else {
  285. return Center(
  286. child: SizedBox.fromSize(
  287. size: const Size.square(24),
  288. child: const CupertinoActivityIndicator(
  289. radius: 8,
  290. ),
  291. ),
  292. );
  293. }
  294. },
  295. ),
  296. ],
  297. ),
  298. const SizedBox(height: 12),
  299. ],
  300. );
  301. }
  302. if (_isImage && _exif != null) {
  303. //remove
  304. // items.add(_getExifWidgets(_exif));
  305. _generateExifForDetails(_exif);
  306. }
  307. if (file.uploadedFileID != null && file.updationTime != null) {
  308. //remove
  309. items.addAll(
  310. [
  311. Row(
  312. children: [
  313. Icon(Icons.cloud_upload_outlined, color: infoColor),
  314. const Padding(padding: EdgeInsets.all(4)),
  315. Text(
  316. getFormattedTime(
  317. DateTime.fromMicrosecondsSinceEpoch(file.updationTime),
  318. ),
  319. style: TextStyle(color: infoColor),
  320. ),
  321. ],
  322. ),
  323. ],
  324. );
  325. }
  326. items.add(
  327. const SizedBox(height: 12),
  328. );
  329. items.add(
  330. Row(
  331. mainAxisAlignment:
  332. _isImage ? MainAxisAlignment.spaceBetween : MainAxisAlignment.end,
  333. children: _getActions(),
  334. ),
  335. );
  336. Widget titleContent;
  337. if (file.uploadedFileID == null ||
  338. file.ownerID != Configuration.instance.getUserID()) {
  339. titleContent = Text(file.getDisplayName());
  340. } else {
  341. titleContent = InkWell(
  342. child: Row(
  343. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  344. children: [
  345. Flexible(
  346. child: Text(
  347. file.getDisplayName(),
  348. style: Theme.of(context).textTheme.headline5,
  349. ),
  350. ),
  351. const SizedBox(width: 16),
  352. Icon(Icons.edit, color: infoColor),
  353. ],
  354. ),
  355. onTap: () async {
  356. await editFilename(context, file);
  357. setState(() {});
  358. },
  359. );
  360. }
  361. // return AlertDialog(
  362. // title: titleContent,
  363. // content: SingleChildScrollView(
  364. // child: ListBody(
  365. // children: items,
  366. // ),
  367. // ),
  368. // );
  369. return Column(
  370. mainAxisSize: MainAxisSize.min,
  371. children: [
  372. Padding(
  373. padding: const EdgeInsets.all(10),
  374. child: Row(
  375. crossAxisAlignment: CrossAxisAlignment.center,
  376. children: [
  377. IconButton(
  378. onPressed: () {
  379. Navigator.pop(context);
  380. },
  381. icon: const Icon(
  382. Icons.close,
  383. ),
  384. ),
  385. const SizedBox(width: 6),
  386. Padding(
  387. padding: const EdgeInsets.only(bottom: 2),
  388. child: Text(
  389. "Details",
  390. style: Theme.of(context).textTheme.bodyText1,
  391. ),
  392. ),
  393. ],
  394. ),
  395. ),
  396. ...listTiles
  397. ],
  398. );
  399. }
  400. List<Widget> _getActions() {
  401. final List<Widget> actions = [];
  402. if (_isImage) {
  403. if (_exif == null) {
  404. actions.add(
  405. TextButton(
  406. child: Row(
  407. mainAxisAlignment: MainAxisAlignment.spaceAround,
  408. children: [
  409. Center(
  410. child: SizedBox.fromSize(
  411. size: const Size.square(24),
  412. child: const CupertinoActivityIndicator(
  413. radius: 8,
  414. ),
  415. ),
  416. ),
  417. const Padding(padding: EdgeInsets.all(4)),
  418. Text(
  419. "EXIF",
  420. style: TextStyle(color: infoColor),
  421. ),
  422. ],
  423. ),
  424. onPressed: () {
  425. showDialog(
  426. context: context,
  427. builder: (BuildContext context) {
  428. return ExifInfoDialog(widget.file);
  429. },
  430. barrierColor: Colors.black87,
  431. );
  432. },
  433. ),
  434. );
  435. } else if (_exif.isNotEmpty) {
  436. actions.add(
  437. TextButton(
  438. child: Row(
  439. mainAxisAlignment: MainAxisAlignment.spaceAround,
  440. children: [
  441. Icon(Icons.feed_outlined, color: infoColor),
  442. const Padding(padding: EdgeInsets.all(4)),
  443. Text(
  444. "View raw EXIF",
  445. style: TextStyle(color: infoColor),
  446. ),
  447. ],
  448. ),
  449. onPressed: () {
  450. showDialog(
  451. context: context,
  452. builder: (BuildContext context) {
  453. return ExifInfoDialog(widget.file);
  454. },
  455. barrierColor: Colors.black87,
  456. );
  457. },
  458. ),
  459. );
  460. } else {
  461. actions.add(
  462. TextButton(
  463. child: Row(
  464. mainAxisAlignment: MainAxisAlignment.spaceAround,
  465. children: [
  466. Icon(
  467. Icons.feed_outlined,
  468. color: Theme.of(context)
  469. .colorScheme
  470. .defaultTextColor
  471. .withOpacity(0.5),
  472. ),
  473. const Padding(padding: EdgeInsets.all(4)),
  474. Text(
  475. "No exif",
  476. style: TextStyle(
  477. color: Theme.of(context)
  478. .colorScheme
  479. .defaultTextColor
  480. .withOpacity(0.5),
  481. ),
  482. ),
  483. ],
  484. ),
  485. onPressed: () {
  486. showShortToast(context, "This image has no exif data");
  487. },
  488. ),
  489. );
  490. }
  491. }
  492. actions.add(
  493. //remove
  494. TextButton(
  495. child: Text(
  496. "Close",
  497. style: TextStyle(
  498. color: infoColor,
  499. ),
  500. ),
  501. onPressed: () {
  502. Navigator.of(context, rootNavigator: true).pop("dialog");
  503. },
  504. ),
  505. );
  506. return actions;
  507. }
  508. _generateExifForDetails(Map<String, IfdTag> exif) {
  509. if (exif["EXIF FocalLength"] != null) {
  510. _exifData["focalLength"] =
  511. (exif["EXIF FocalLength"].values.toList()[0] as Ratio).numerator /
  512. (exif["EXIF FocalLength"].values.toList()[0] as Ratio)
  513. .denominator;
  514. }
  515. if (exif["EXIF FNumber"] != null) {
  516. _exifData["fNumber"] =
  517. (exif["EXIF FNumber"].values.toList()[0] as Ratio).numerator /
  518. (exif["EXIF FNumber"].values.toList()[0] as Ratio).denominator;
  519. }
  520. if (exif["EXIF ExifImageWidth"] != null &&
  521. exif["EXIF ExifImageLength"] != null) {
  522. _exifData["resolution"] = exif["EXIF ExifImageWidth"].toString() +
  523. " x " +
  524. exif["EXIF ExifImageLength"].toString();
  525. _exifData['megaPixels'] = ((exif["Image ImageWidth"].values.firstAsInt() *
  526. exif["Image ImageLength"].values.firstAsInt()) /
  527. 1000000)
  528. .toStringAsFixed(1);
  529. } else if (exif["Image ImageWidth"] != null &&
  530. exif["Image ImageLength"] != null) {
  531. _exifData["resolution"] = exif["Image ImageWidth"].toString() +
  532. " x " +
  533. exif["Image ImageLength"].toString();
  534. }
  535. if (exif["Image Make"] != null && exif["Image Model"] != null) {
  536. _exifData["takenOnDevice"] =
  537. exif["Image Make"].toString() + " " + exif["Image Model"].toString();
  538. }
  539. if (exif["EXIF ExposureTime"] != null) {
  540. _exifData["exposureTime"] = exif["EXIF ExposureTime"].toString();
  541. }
  542. if (exif["EXIF ISOSpeedRatings"] != null) {
  543. _exifData['ISO'] = exif["EXIF ISOSpeedRatings"].toString();
  544. }
  545. }
  546. Widget _getExifWidgets(Map<String, IfdTag> exif) {
  547. final focalLength = exif["EXIF FocalLength"] != null
  548. ? (exif["EXIF FocalLength"].values.toList()[0] as Ratio).numerator /
  549. (exif["EXIF FocalLength"].values.toList()[0] as Ratio)
  550. .denominator //to remove
  551. : null;
  552. final fNumber = exif["EXIF FNumber"] != null
  553. ? (exif["EXIF FNumber"].values.toList()[0] as Ratio).numerator /
  554. (exif["EXIF FNumber"].values.toList()[0] as Ratio)
  555. .denominator //to remove
  556. : null;
  557. final List<Widget> children = [];
  558. if (exif["EXIF ExifImageWidth"] != null &&
  559. exif["EXIF ExifImageLength"] != null) {
  560. children.addAll([
  561. Row(
  562. children: [
  563. Icon(Icons.photo_size_select_actual_outlined, color: infoColor),
  564. const Padding(padding: EdgeInsets.all(4)),
  565. Text(
  566. exif["EXIF ExifImageWidth"].toString() +
  567. " x " +
  568. exif["EXIF ExifImageLength"].toString(),
  569. style: TextStyle(color: infoColor),
  570. ),
  571. ],
  572. ),
  573. const Padding(padding: EdgeInsets.all(6)),
  574. ]);
  575. } else if (exif["Image ImageWidth"] != null &&
  576. exif["Image ImageLength"] != null) {
  577. children.addAll([
  578. Row(
  579. children: [
  580. Icon(Icons.photo_size_select_actual_outlined, color: infoColor),
  581. const Padding(padding: EdgeInsets.all(4)),
  582. Text(
  583. exif["Image ImageWidth"].toString() +
  584. " x " +
  585. exif["Image ImageLength"].toString(),
  586. style: TextStyle(color: infoColor),
  587. ),
  588. ],
  589. ),
  590. const Padding(padding: EdgeInsets.all(6)),
  591. ]);
  592. }
  593. if (exif["Image Make"] != null && exif["Image Model"] != null) {
  594. children.addAll(
  595. [
  596. Row(
  597. children: [
  598. Icon(Icons.camera_outlined, color: infoColor),
  599. const Padding(padding: EdgeInsets.all(4)),
  600. Flexible(
  601. child: Text(
  602. exif["Image Make"].toString() +
  603. " " +
  604. exif["Image Model"].toString(),
  605. style: TextStyle(color: infoColor),
  606. overflow: TextOverflow.clip,
  607. ),
  608. ),
  609. ],
  610. ),
  611. const Padding(padding: EdgeInsets.all(6)),
  612. ],
  613. );
  614. }
  615. if (fNumber != null) {
  616. children.addAll([
  617. Row(
  618. children: [
  619. Icon(CupertinoIcons.f_cursive, color: infoColor),
  620. const Padding(padding: EdgeInsets.all(4)),
  621. Text(
  622. fNumber.toString(),
  623. style: TextStyle(color: infoColor),
  624. ),
  625. ],
  626. ),
  627. const Padding(padding: EdgeInsets.all(6)),
  628. ]);
  629. }
  630. if (focalLength != null) {
  631. children.addAll([
  632. Row(
  633. children: [
  634. Icon(Icons.center_focus_strong_outlined, color: infoColor),
  635. const Padding(padding: EdgeInsets.all(4)),
  636. Text(
  637. focalLength.toString() + " mm",
  638. style: TextStyle(color: infoColor),
  639. ),
  640. ],
  641. ),
  642. const Padding(padding: EdgeInsets.all(6)),
  643. ]);
  644. }
  645. if (exif["EXIF ExposureTime"] != null) {
  646. children.addAll([
  647. Row(
  648. children: [
  649. Icon(Icons.shutter_speed, color: infoColor),
  650. const Padding(padding: EdgeInsets.all(4)),
  651. Text(
  652. exif["EXIF ExposureTime"].toString(),
  653. style: TextStyle(color: infoColor),
  654. ),
  655. ],
  656. ),
  657. const Padding(padding: EdgeInsets.all(6)),
  658. ]);
  659. }
  660. return Column(
  661. children: children,
  662. );
  663. }
  664. Widget _getFileSize() {
  665. return FutureBuilder(
  666. future: getFile(widget.file).then((f) => f.length()),
  667. builder: (context, snapshot) {
  668. if (snapshot.hasData) {
  669. return Text(
  670. (snapshot.data / (1024 * 1024)).toStringAsFixed(2) + " MB",
  671. );
  672. } else {
  673. return Center(
  674. child: SizedBox.fromSize(
  675. size: const Size.square(24),
  676. child: const CupertinoActivityIndicator(
  677. radius: 8,
  678. ),
  679. ),
  680. );
  681. }
  682. },
  683. );
  684. }
  685. Widget _getVideoDuration() {
  686. if (widget.file.duration != 0) {
  687. return Text(
  688. secondsToHHMMSS(widget.file.duration),
  689. );
  690. }
  691. return FutureBuilder(
  692. future: widget.file.getAsset(),
  693. builder: (context, snapshot) {
  694. if (snapshot.hasData) {
  695. return Text(
  696. snapshot.data.videoDuration.toString().split(".")[0],
  697. );
  698. } else {
  699. return Center(
  700. child: SizedBox.fromSize(
  701. size: const Size.square(24),
  702. child: const CupertinoActivityIndicator(
  703. radius: 8,
  704. ),
  705. ),
  706. );
  707. }
  708. },
  709. );
  710. }
  711. void _showDateTimePicker(File file) async {
  712. final dateResult = await DatePicker.showDatePicker(
  713. context,
  714. minTime: DateTime(1800, 1, 1),
  715. maxTime: DateTime.now(),
  716. currentTime: DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
  717. locale: LocaleType.en,
  718. theme: Theme.of(context).colorScheme.dateTimePickertheme,
  719. );
  720. if (dateResult == null) {
  721. return;
  722. }
  723. final dateWithTimeResult = await DatePicker.showTime12hPicker(
  724. context,
  725. showTitleActions: true,
  726. currentTime: dateResult,
  727. locale: LocaleType.en,
  728. theme: Theme.of(context).colorScheme.dateTimePickertheme,
  729. );
  730. if (dateWithTimeResult != null) {
  731. if (await editTime(
  732. context,
  733. List.of([widget.file]),
  734. dateWithTimeResult.microsecondsSinceEpoch,
  735. )) {
  736. widget.file.creationTime = dateWithTimeResult.microsecondsSinceEpoch;
  737. setState(() {});
  738. }
  739. }
  740. }
  741. }
  742. class DividerWithPadding extends StatelessWidget {
  743. const DividerWithPadding({Key key}) : super(key: key);
  744. @override
  745. Widget build(BuildContext context) {
  746. return const Padding(
  747. padding: EdgeInsets.fromLTRB(70, 0, 20, 0),
  748. child: Divider(
  749. thickness: 0.5,
  750. ),
  751. );
  752. }
  753. }
  754. enum Status {
  755. loading,
  756. exifIsAvailable,
  757. noExif,
  758. }
  759. class RawExifButton extends StatelessWidget {
  760. final File file;
  761. final Map<String, IfdTag> exif;
  762. const RawExifButton(this.exif, this.file, {Key key}) : super(key: key);
  763. @override
  764. Widget build(BuildContext context) {
  765. Status exifStatus = Status.loading;
  766. if (exif == null) {
  767. exifStatus = Status.loading;
  768. } else if (exif.isNotEmpty) {
  769. exifStatus = Status.exifIsAvailable;
  770. } else {
  771. exifStatus = Status.noExif;
  772. }
  773. return GestureDetector(
  774. child: Container(
  775. height: 40,
  776. width: 140,
  777. decoration: BoxDecoration(
  778. color: Theme.of(context)
  779. .colorScheme
  780. .inverseBackgroundColor
  781. .withOpacity(0.12),
  782. borderRadius: const BorderRadius.all(
  783. Radius.circular(20),
  784. ),
  785. ),
  786. child: Center(
  787. child: exifStatus == Status.loading
  788. ? Row(
  789. mainAxisAlignment: MainAxisAlignment.center,
  790. children: [
  791. CupertinoActivityIndicator(
  792. radius: 8,
  793. ),
  794. const SizedBox(
  795. width: 8,
  796. ),
  797. Text('EXIF')
  798. ],
  799. )
  800. : exifStatus == Status.exifIsAvailable
  801. ? Row(
  802. mainAxisAlignment: MainAxisAlignment.center,
  803. children: [
  804. Icon(Icons.feed_outlined),
  805. SizedBox(
  806. width: 8,
  807. ),
  808. Text('Raw EXIF'),
  809. ],
  810. )
  811. : Row(
  812. mainAxisAlignment: MainAxisAlignment.center,
  813. children: [
  814. Icon(Icons.feed_outlined),
  815. SizedBox(
  816. width: 8,
  817. ),
  818. Text('No EXIF'),
  819. ],
  820. ),
  821. ),
  822. ),
  823. onTap:
  824. exifStatus == Status.loading || exifStatus == Status.exifIsAvailable
  825. ? () {
  826. showDialog(
  827. context: context,
  828. builder: (BuildContext context) {
  829. return ExifInfoDialog(file);
  830. },
  831. barrierColor: Colors.black87,
  832. );
  833. }
  834. : exifStatus == Status.noExif
  835. ? () {
  836. showShortToast(context, "This image has no exif data");
  837. }
  838. : null,
  839. );
  840. }
  841. }