exif_info_dialog.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/models/file.dart';
  4. import 'package:photos/ui/common/loading_widget.dart';
  5. import 'package:photos/utils/exif_util.dart';
  6. class ExifInfoDialog extends StatefulWidget {
  7. final File file;
  8. const ExifInfoDialog(this.file, {Key key}) : super(key: key);
  9. @override
  10. State<ExifInfoDialog> createState() => _ExifInfoDialogState();
  11. }
  12. class _ExifInfoDialogState extends State<ExifInfoDialog> {
  13. @override
  14. Widget build(BuildContext context) {
  15. final scrollController = ScrollController();
  16. return AlertDialog(
  17. title: Text(
  18. widget.file.title,
  19. style: Theme.of(context).textTheme.headline5,
  20. ),
  21. content: Scrollbar(
  22. controller: scrollController,
  23. thumbVisibility: true,
  24. child: SingleChildScrollView(
  25. controller: scrollController,
  26. child: _getInfo(),
  27. ),
  28. ),
  29. actions: [
  30. TextButton(
  31. child: Text(
  32. "Close",
  33. style: Theme.of(context).textTheme.bodyText1,
  34. ),
  35. onPressed: () {
  36. Navigator.of(context, rootNavigator: true).pop('dialog');
  37. },
  38. ),
  39. ],
  40. );
  41. }
  42. Widget _getInfo() {
  43. return FutureBuilder(
  44. future: getExif(widget.file),
  45. builder: (BuildContext context, AsyncSnapshot snapshot) {
  46. if (snapshot.hasData) {
  47. final exif = snapshot.data;
  48. String data = "";
  49. for (String key in exif.keys) {
  50. data += "$key: ${exif[key]}\n";
  51. }
  52. if (data.isEmpty) {
  53. data = "no exif data found";
  54. }
  55. return Container(
  56. padding: const EdgeInsets.all(2),
  57. color: Colors.white.withOpacity(0.05),
  58. child: Center(
  59. child: Padding(
  60. padding: const EdgeInsets.all(4),
  61. child: Text(
  62. data,
  63. style: TextStyle(
  64. fontSize: 14,
  65. fontFeatures: const [
  66. FontFeature.tabularFigures(),
  67. ],
  68. height: 1.4,
  69. color: Theme.of(context)
  70. .colorScheme
  71. .onSurface
  72. .withOpacity(0.7),
  73. ),
  74. ),
  75. ),
  76. ),
  77. );
  78. } else {
  79. return const EnteLoadingWidget();
  80. }
  81. },
  82. );
  83. }
  84. }