RawExifButton.dart 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:exif/exif.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:photos/ente_theme_data.dart';
  5. import "package:photos/models/file.dart";
  6. import 'package:photos/ui/viewer/file/exif_info_dialog.dart';
  7. import 'package:photos/utils/toast_util.dart';
  8. enum Status {
  9. loading,
  10. exifIsAvailable,
  11. noExif,
  12. }
  13. class RawExifButton extends StatelessWidget {
  14. final File file;
  15. final Map<String, IfdTag> exif;
  16. const RawExifButton(this.exif, this.file, {Key key}) : super(key: key);
  17. @override
  18. Widget build(BuildContext context) {
  19. Status exifStatus = Status.loading;
  20. if (exif == null) {
  21. exifStatus = Status.loading;
  22. } else if (exif.isNotEmpty) {
  23. exifStatus = Status.exifIsAvailable;
  24. } else {
  25. exifStatus = Status.noExif;
  26. }
  27. return GestureDetector(
  28. onTap:
  29. exifStatus == Status.loading || exifStatus == Status.exifIsAvailable
  30. ? () {
  31. showDialog(
  32. context: context,
  33. builder: (BuildContext context) {
  34. return ExifInfoDialog(file);
  35. },
  36. barrierColor: Colors.black87,
  37. );
  38. }
  39. : exifStatus == Status.noExif
  40. ? () {
  41. showShortToast(context, "This image has no exif data");
  42. }
  43. : null,
  44. child: Container(
  45. height: 40,
  46. width: 140,
  47. decoration: BoxDecoration(
  48. color: Theme.of(context)
  49. .colorScheme
  50. .inverseBackgroundColor
  51. .withOpacity(0.12),
  52. borderRadius: const BorderRadius.all(
  53. Radius.circular(20),
  54. ),
  55. ),
  56. child: Center(
  57. child: exifStatus == Status.loading
  58. ? Row(
  59. mainAxisAlignment: MainAxisAlignment.center,
  60. children: const [
  61. CupertinoActivityIndicator(
  62. radius: 8,
  63. ),
  64. SizedBox(
  65. width: 8,
  66. ),
  67. Text('EXIF')
  68. ],
  69. )
  70. : exifStatus == Status.exifIsAvailable
  71. ? Row(
  72. mainAxisAlignment: MainAxisAlignment.center,
  73. children: const [
  74. Icon(Icons.feed_outlined),
  75. SizedBox(
  76. width: 8,
  77. ),
  78. Text('Raw EXIF'),
  79. ],
  80. )
  81. : Row(
  82. mainAxisAlignment: MainAxisAlignment.center,
  83. children: const [
  84. Icon(Icons.feed_outlined),
  85. SizedBox(
  86. width: 8,
  87. ),
  88. Text('No EXIF'),
  89. ],
  90. ),
  91. ),
  92. ),
  93. );
  94. }
  95. }