123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- import "dart:io";
- import "package:exif/exif.dart";
- import "package:flutter/cupertino.dart";
- import "package:flutter/material.dart";
- import "package:photos/core/configuration.dart";
- import "package:photos/ente_theme_data.dart";
- import "package:photos/models/file.dart";
- import "package:photos/models/file_type.dart";
- import "package:photos/services/collections_service.dart";
- import "package:photos/ui/viewer/file/exif_info_dialog.dart";
- import "package:photos/utils/date_time_util.dart";
- import "package:photos/utils/exif_util.dart";
- import "package:photos/utils/file_util.dart";
- import "package:photos/utils/magic_util.dart";
- import "package:photos/utils/toast_util.dart";
- class FileInfoWidget extends StatefulWidget {
- final File file;
- const FileInfoWidget(
- this.file, {
- Key key,
- }) : super(key: key);
- @override
- State<FileInfoWidget> createState() => _FileInfoWidgetState();
- }
- class _FileInfoWidgetState extends State<FileInfoWidget> {
- Map<String, IfdTag> _exif;
- final Map<String, dynamic> _exifData = {
- "focalLength": null,
- "fNumber": null,
- "resolution": null,
- "takenOnDevice": null,
- "exposureTime": null,
- "ISO": null,
- "megaPixels": null
- };
- bool _isImage = false;
- Color infoColor;
- @override
- void initState() {
- debugPrint('file_info_dialog initState' + _exifData.toString());
- _isImage = widget.file.fileType == FileType.image ||
- widget.file.fileType == FileType.livePhoto;
- if (_isImage) {
- getExif(widget.file).then((exif) {
- setState(() {
- _exif = exif;
- });
- });
- }
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- final file = widget.file;
- final dateTime = DateTime.fromMicrosecondsSinceEpoch(file.creationTime);
- final dateTimeForUpdationTime =
- DateTime.fromMicrosecondsSinceEpoch(file.updationTime);
- infoColor =
- Theme.of(context).colorScheme.onSurface.withOpacity(0.85); //remove
- if (_isImage && _exif != null) {
- // items.add(_getExifWidgets(_exif));
- _generateExifForDetails(_exif);
- }
- final bool showExifListTile = _exifData["focalLength"] != null ||
- _exifData["fNumber"] != null ||
- _exifData["takenOnDevice"] != null ||
- _exifData["exposureTime"] != null ||
- _exifData["ISO"] != null;
- var listTiles = <Widget>[
- ListTile(
- leading: const Padding(
- padding: EdgeInsets.only(top: 8, left: 6),
- child: Icon(Icons.calendar_today_rounded),
- ),
- title: Text(
- getFullDate(
- DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
- ),
- ),
- subtitle: Text(
- getTimeIn12hrFormat(dateTime) + " " + dateTime.timeZoneName,
- style: Theme.of(context)
- .textTheme
- .bodyText2
- .copyWith(color: Colors.black.withOpacity(0.5)),
- ),
- trailing: (widget.file.ownerID == null ||
- widget.file.ownerID ==
- Configuration.instance.getUserID()) &&
- widget.file.uploadedFileID != null
- ? IconButton(
- onPressed: () {
- PopupMenuItem(
- value: 2,
- child: Row(
- children: [
- Icon(
- Platform.isAndroid
- ? Icons.access_time_rounded
- : CupertinoIcons.time,
- color: Theme.of(context).iconTheme.color,
- ),
- const Padding(
- padding: EdgeInsets.all(8),
- ),
- const Text("Edit time"),
- ],
- ),
- );
- },
- icon: const Icon(Icons.edit),
- )
- : const SizedBox.shrink(),
- ),
- const DividerWithPadding(),
- ListTile(
- leading: const Padding(
- padding: EdgeInsets.only(top: 8, left: 6),
- child: Icon(
- Icons.image,
- ),
- ),
- title: Text(
- file.getDisplayName(),
- ),
- subtitle: Row(
- children: [
- _getFileSize(),
- ],
- ),
- trailing: file.uploadedFileID == null ||
- file.ownerID != Configuration.instance.getUserID()
- ? const SizedBox.shrink()
- : IconButton(
- onPressed: () async {
- await editFilename(context, file);
- setState(() {});
- },
- icon: const Icon(Icons.edit),
- ),
- ),
- const DividerWithPadding(),
- ListTile(
- leading: const Padding(
- padding: EdgeInsets.only(left: 6),
- child: Icon(Icons.folder_outlined),
- ),
- title: Text(
- file.deviceFolder ??
- CollectionsService.instance
- .getCollectionByID(file.collectionID)
- .name,
- ),
- ),
- const DividerWithPadding(),
- showExifListTile
- ? ListTile(
- leading: const Padding(
- padding: EdgeInsets.only(left: 6),
- child: Icon(Icons.camera_rounded),
- ),
- title: Text(_exifData["takenOnDevice"] ?? "--"),
- subtitle: Row(
- children: [
- _exifData["fNumber"] != null
- ? Padding(
- padding: const EdgeInsets.only(right: 10),
- child: Text('ƒ/' + _exifData["fNumber"].toString()),
- )
- : const SizedBox.shrink(),
- _exifData["exposureTime"] != null
- ? Padding(
- padding: const EdgeInsets.only(right: 10),
- child: Text(_exifData["exposureTime"]),
- )
- : const SizedBox.shrink(),
- _exifData["focalLength"] != null
- ? Padding(
- padding: const EdgeInsets.only(right: 10),
- child:
- Text(_exifData["focalLength"].toString() + "mm"),
- )
- : const SizedBox.shrink(),
- _exifData["ISO"] != null
- ? Padding(
- padding: const EdgeInsets.only(right: 10),
- child: Text("ISO" + _exifData["ISO"].toString()),
- )
- : const SizedBox.shrink(),
- ],
- ),
- )
- : const SizedBox.shrink(),
- showExifListTile ? const DividerWithPadding() : const SizedBox.shrink(),
- (file.uploadedFileID != null && file.updationTime != null)
- ? ListTile(
- leading: const Padding(
- padding: EdgeInsets.only(top: 8, left: 6),
- child: Icon(Icons.cloud_upload_outlined),
- ),
- title: Text(
- getFullDate(
- DateTime.fromMicrosecondsSinceEpoch(file.updationTime),
- ),
- ),
- subtitle: Text(
- getTimeIn12hrFormat(dateTimeForUpdationTime) +
- " " +
- dateTimeForUpdationTime.timeZoneName,
- style: Theme.of(context)
- .textTheme
- .bodyText2
- .copyWith(color: Colors.black.withOpacity(0.5)),
- ),
- )
- : const SizedBox.shrink(),
- ];
- var items = <Widget>[
- Row(
- children: [
- Icon(Icons.calendar_today_outlined, color: infoColor),
- const SizedBox(height: 8),
- Text(
- getFormattedTime(
- DateTime.fromMicrosecondsSinceEpoch(file.creationTime),
- ),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const SizedBox(height: 12),
- Row(
- children: [
- Icon(Icons.folder_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- file.deviceFolder ??
- CollectionsService.instance
- .getCollectionByID(file.collectionID)
- .name,
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const SizedBox(height: 12),
- ];
- items.addAll(
- [
- Row(
- children: [
- Icon(Icons.sd_storage_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- _getFileSize(),
- ],
- ),
- const SizedBox(height: 12),
- ],
- );
- if (file.localID != null && !_isImage) {
- items.addAll(
- [
- Row(
- children: [
- Icon(Icons.timer_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- FutureBuilder(
- future: file.getAsset(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return Text(
- snapshot.data.videoDuration.toString().split(".")[0],
- style: TextStyle(color: infoColor),
- );
- } else {
- return Center(
- child: SizedBox.fromSize(
- size: const Size.square(24),
- child: const CupertinoActivityIndicator(
- radius: 8,
- ),
- ),
- );
- }
- },
- ),
- ],
- ),
- const SizedBox(height: 12),
- ],
- );
- }
- if (_isImage && _exif != null) {
- //remove
- // items.add(_getExifWidgets(_exif));
- _generateExifForDetails(_exif);
- }
- if (file.uploadedFileID != null && file.updationTime != null) {
- items.addAll(
- [
- Row(
- children: [
- Icon(Icons.cloud_upload_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- getFormattedTime(
- DateTime.fromMicrosecondsSinceEpoch(file.updationTime),
- ),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- ],
- );
- }
- items.add(
- const SizedBox(height: 12),
- );
- items.add(
- Row(
- mainAxisAlignment:
- _isImage ? MainAxisAlignment.spaceBetween : MainAxisAlignment.end,
- children: _getActions(),
- ),
- );
- Widget titleContent;
- if (file.uploadedFileID == null ||
- file.ownerID != Configuration.instance.getUserID()) {
- titleContent = Text(file.getDisplayName());
- } else {
- titleContent = InkWell(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Flexible(
- child: Text(
- file.getDisplayName(),
- style: Theme.of(context).textTheme.headline5,
- ),
- ),
- const SizedBox(width: 16),
- Icon(Icons.edit, color: infoColor),
- ],
- ),
- onTap: () async {
- await editFilename(context, file);
- setState(() {});
- },
- );
- }
- // return AlertDialog(
- // title: titleContent,
- // content: SingleChildScrollView(
- // child: ListBody(
- // children: items,
- // ),
- // ),
- // );
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Padding(
- padding: const EdgeInsets.all(10),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- IconButton(
- onPressed: () {
- Navigator.pop(context);
- },
- icon: const Icon(
- Icons.close,
- ),
- ),
- const SizedBox(width: 6),
- Padding(
- padding: const EdgeInsets.only(bottom: 2),
- child: Text(
- "Details",
- style: Theme.of(context).textTheme.bodyText1,
- ),
- ),
- ],
- ),
- ),
- ...listTiles
- ],
- );
- }
- List<Widget> _getActions() {
- final List<Widget> actions = [];
- if (_isImage) {
- if (_exif == null) {
- actions.add(
- TextButton(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- Center(
- child: SizedBox.fromSize(
- size: const Size.square(24),
- child: const CupertinoActivityIndicator(
- radius: 8,
- ),
- ),
- ),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- "EXIF",
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- onPressed: () {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return ExifInfoDialog(widget.file);
- },
- barrierColor: Colors.black87,
- );
- },
- ),
- );
- } else if (_exif.isNotEmpty) {
- actions.add(
- TextButton(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- Icon(Icons.feed_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- "View raw EXIF",
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- onPressed: () {
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return ExifInfoDialog(widget.file);
- },
- barrierColor: Colors.black87,
- );
- },
- ),
- );
- } else {
- actions.add(
- TextButton(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- Icon(
- Icons.feed_outlined,
- color: Theme.of(context)
- .colorScheme
- .defaultTextColor
- .withOpacity(0.5),
- ),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- "No exif",
- style: TextStyle(
- color: Theme.of(context)
- .colorScheme
- .defaultTextColor
- .withOpacity(0.5),
- ),
- ),
- ],
- ),
- onPressed: () {
- showShortToast(context, "This image has no exif data");
- },
- ),
- );
- }
- }
- actions.add(
- TextButton(
- child: Text(
- "Close",
- style: TextStyle(
- color: infoColor,
- ),
- ),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop("dialog");
- },
- ),
- );
- return actions;
- }
- _generateExifForDetails(Map<String, IfdTag> exif) {
- if (exif["EXIF FocalLength"] != null) {
- _exifData["focalLength"] =
- (exif["EXIF FocalLength"].values.toList()[0] as Ratio).numerator /
- (exif["EXIF FocalLength"].values.toList()[0] as Ratio)
- .denominator;
- }
- if (exif["EXIF FNumber"] != null) {
- _exifData["fNumber"] =
- (exif["EXIF FNumber"].values.toList()[0] as Ratio).numerator /
- (exif["EXIF FNumber"].values.toList()[0] as Ratio).denominator;
- }
- if (exif["EXIF ExifImageWidth"] != null &&
- exif["EXIF ExifImageLength"] != null) {
- _exifData["resolution"] = exif["EXIF ExifImageWidth"].toString() +
- " x " +
- exif["EXIF ExifImageLength"].toString();
- _exifData['megaPixels'] = ((exif["Image ImageWidth"].values.firstAsInt() *
- exif["Image ImageLength"].values.firstAsInt()) /
- 1000000)
- .toStringAsFixed(1);
- } else if (exif["Image ImageWidth"] != null &&
- exif["Image ImageLength"] != null) {
- _exifData["resolution"] = exif["Image ImageWidth"].toString() +
- " x " +
- exif["Image ImageLength"].toString();
- }
- if (exif["Image Make"] != null && exif["Image Model"] != null) {
- _exifData["takenOnDevice"] =
- exif["Image Make"].toString() + " " + exif["Image Model"].toString();
- }
- if (exif["EXIF ExposureTime"] != null) {
- _exifData["exposureTime"] = exif["EXIF ExposureTime"].toString();
- }
- if (exif["EXIF ISOSpeedRatings"] != null) {
- _exifData['ISO'] = exif["EXIF ISOSpeedRatings"].toString();
- }
- }
- Widget _getExifWidgets(Map<String, IfdTag> exif) {
- final focalLength = exif["EXIF FocalLength"] != null
- ? (exif["EXIF FocalLength"].values.toList()[0] as Ratio).numerator /
- (exif["EXIF FocalLength"].values.toList()[0] as Ratio)
- .denominator //to remove
- : null;
- final fNumber = exif["EXIF FNumber"] != null
- ? (exif["EXIF FNumber"].values.toList()[0] as Ratio).numerator /
- (exif["EXIF FNumber"].values.toList()[0] as Ratio)
- .denominator //to remove
- : null;
- final List<Widget> children = [];
- if (exif["EXIF ExifImageWidth"] != null &&
- exif["EXIF ExifImageLength"] != null) {
- children.addAll([
- Row(
- children: [
- Icon(Icons.photo_size_select_actual_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- exif["EXIF ExifImageWidth"].toString() +
- " x " +
- exif["EXIF ExifImageLength"].toString(),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ]);
- } else if (exif["Image ImageWidth"] != null &&
- exif["Image ImageLength"] != null) {
- children.addAll([
- Row(
- children: [
- Icon(Icons.photo_size_select_actual_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- exif["Image ImageWidth"].toString() +
- " x " +
- exif["Image ImageLength"].toString(),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ]);
- }
- if (exif["Image Make"] != null && exif["Image Model"] != null) {
- children.addAll(
- [
- Row(
- children: [
- Icon(Icons.camera_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Flexible(
- child: Text(
- exif["Image Make"].toString() +
- " " +
- exif["Image Model"].toString(),
- style: TextStyle(color: infoColor),
- overflow: TextOverflow.clip,
- ),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ],
- );
- }
- if (fNumber != null) {
- children.addAll([
- Row(
- children: [
- Icon(CupertinoIcons.f_cursive, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- fNumber.toString(),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ]);
- }
- if (focalLength != null) {
- children.addAll([
- Row(
- children: [
- Icon(Icons.center_focus_strong_outlined, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- focalLength.toString() + " mm",
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ]);
- }
- if (exif["EXIF ExposureTime"] != null) {
- children.addAll([
- Row(
- children: [
- Icon(Icons.shutter_speed, color: infoColor),
- const Padding(padding: EdgeInsets.all(4)),
- Text(
- exif["EXIF ExposureTime"].toString(),
- style: TextStyle(color: infoColor),
- ),
- ],
- ),
- const Padding(padding: EdgeInsets.all(6)),
- ]);
- }
- return Column(
- children: children,
- );
- }
- Widget _getFileSize() {
- return FutureBuilder(
- future: getFile(widget.file).then((f) => f.length()),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return Text(
- (snapshot.data / (1024 * 1024)).toStringAsFixed(2) + " MB",
- );
- } else {
- return Center(
- child: SizedBox.fromSize(
- size: const Size.square(24),
- child: const CupertinoActivityIndicator(
- radius: 8,
- ),
- ),
- );
- }
- },
- );
- }
- }
- class DividerWithPadding extends StatelessWidget {
- const DividerWithPadding({Key key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return const Padding(
- padding: EdgeInsets.fromLTRB(70, 0, 20, 0),
- child: Divider(
- thickness: 0.5,
- ),
- );
- }
- }
|