Преглед изворни кода

redesigned time and date of file info

ashilkn пре 3 година
родитељ
комит
1c9dc6566e
2 измењених фајлова са 81 додато и 0 уклоњено
  1. 51 0
      lib/ui/file_info_dialog.dart
  2. 30 0
      lib/utils/date_time_util.dart

+ 51 - 0
lib/ui/file_info_dialog.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:exif/exif.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
@@ -47,7 +49,55 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
   @override
   Widget build(BuildContext context) {
     final file = widget.file;
+    final dateTime = DateTime.fromMicrosecondsSinceEpoch(file.creationTime);
     infoColor = Theme.of(context).colorScheme.onSurface.withOpacity(0.85);
+    var listTiles = <Widget>[
+      ListTile(
+        leading: Padding(
+          padding: const 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,
+                        ),
+                        Padding(
+                          padding: EdgeInsets.all(8),
+                        ),
+                        Text("Edit time"),
+                      ],
+                    ),
+                  );
+                },
+                icon: Icon(Icons.edit),
+              )
+            : const SizedBox.shrink(),
+      ),
+    ];
     var items = <Widget>[
       Row(
         children: [
@@ -214,6 +264,7 @@ class _FileInfoWidgetState extends State<FileInfoWidget> {
             ],
           ),
         ),
+        ...listTiles
       ],
     );
   }

+ 30 - 0
lib/utils/date_time_util.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:intl/intl.dart';
 
 Map<int, String> _months = {
   1: "Jan",
@@ -41,10 +42,12 @@ Map<int, String> _days = {
 };
 
 String getMonthAndYear(DateTime dateTime) {
+  //Jun 2022
   return _months[dateTime.month] + " " + dateTime.year.toString();
 }
 
 String getDayAndMonth(DateTime dateTime) {
+  //Thu, 30 Jun
   return _days[dateTime.weekday] +
       ", " +
       dateTime.day.toString() +
@@ -53,6 +56,7 @@ String getDayAndMonth(DateTime dateTime) {
 }
 
 String getDateAndMonthAndYear(DateTime dateTime) {
+  //30 Jun, 2022
   return dateTime.day.toString() +
       " " +
       _months[dateTime.month] +
@@ -60,6 +64,14 @@ String getDateAndMonthAndYear(DateTime dateTime) {
       dateTime.year.toString();
 }
 
+// String getFullMonthAndDateAndYear(DateTime dateTime) {
+//   return _fullMonths[dateTime.month] +
+//       " " +
+//       dateTime.day.toString() +
+//       ", " +
+//       dateTime.year.toString();
+// }
+
 String getDay(DateTime dateTime) {
   return _days[dateTime.weekday];
 }
@@ -77,6 +89,7 @@ String getAbbreviationOfYear(DateTime dateTime) {
 }
 
 String getTime(DateTime dateTime) {
+  //14:32
   final hours = dateTime.hour > 9
       ? dateTime.hour.toString()
       : "0" + dateTime.hour.toString();
@@ -86,7 +99,13 @@ String getTime(DateTime dateTime) {
   return hours + ":" + minutes;
 }
 
+String getTimeIn12hrFormat(DateTime dateTime) {
+  //11:22 AM
+  return DateFormat.jm().format(dateTime);
+}
+
 String getFormattedTime(DateTime dateTime) {
+  //Thu, Jun 30, 2022 - 14:32
   return getDay(dateTime) +
       ", " +
       getMonth(dateTime) +
@@ -99,6 +118,7 @@ String getFormattedTime(DateTime dateTime) {
 }
 
 String getFormattedDate(DateTime dateTime) {
+  //30 Jun'22
   return dateTime.day.toString() +
       " " +
       getMonth(dateTime) +
@@ -106,6 +126,16 @@ String getFormattedDate(DateTime dateTime) {
       getAbbreviationOfYear(dateTime);
 }
 
+String getFullDate(DateTime dateTime) {
+  return getDay(dateTime) +
+      ", " +
+      getMonth(dateTime) +
+      " " +
+      dateTime.day.toString() +
+      " " +
+      dateTime.year.toString();
+}
+
 String daysLeft(int futureTime) {
   int daysLeft = ((futureTime - DateTime.now().microsecondsSinceEpoch) /
           Duration.microsecondsPerDay)