exif_info_dialog.dart 2.4 KB

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