Przeglądaj źródła

Link expirary: Fix UI issue in custom time option

Neeraj Gupta 2 lat temu
rodzic
commit
ec40540486
1 zmienionych plików z 17 dodań i 6 usunięć
  1. 17 6
      lib/ui/sharing/manage_links_widget.dart

+ 17 - 6
lib/ui/sharing/manage_links_widget.dart

@@ -304,10 +304,13 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
                   CupertinoButton(
                   CupertinoButton(
                     onPressed: () async {
                     onPressed: () async {
                       int newValidTill = -1;
                       int newValidTill = -1;
+                      bool hasSelectedCustom = false;
                       final int expireAfterInMicroseconds =
                       final int expireAfterInMicroseconds =
                           _selectedExpiry.item3;
                           _selectedExpiry.item3;
                       // need to manually select time
                       // need to manually select time
                       if (expireAfterInMicroseconds < 0) {
                       if (expireAfterInMicroseconds < 0) {
+                        hasSelectedCustom = true;
+                        Navigator.of(context).pop('');
                         final timeInMicrosecondsFromEpoch =
                         final timeInMicrosecondsFromEpoch =
                             await _showDateTimePicker();
                             await _showDateTimePicker();
                         if (timeInMicrosecondsFromEpoch != null) {
                         if (timeInMicrosecondsFromEpoch != null) {
@@ -320,14 +323,12 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
                         newValidTill = DateTime.now().microsecondsSinceEpoch +
                         newValidTill = DateTime.now().microsecondsSinceEpoch +
                             expireAfterInMicroseconds;
                             expireAfterInMicroseconds;
                       }
                       }
+                      if (!hasSelectedCustom) {
+                        Navigator.of(context).pop('');
+                      }
                       if (newValidTill >= 0) {
                       if (newValidTill >= 0) {
-                        await _updateUrlSettings(
-                          context,
-                          {'validTill': newValidTill},
-                        );
-                        setState(() {});
+                        await updateTime(newValidTill);
                       }
                       }
-                      Navigator.of(context).pop('');
                     },
                     },
                     padding: const EdgeInsets.symmetric(
                     padding: const EdgeInsets.symmetric(
                       horizontal: 16.0,
                       horizontal: 16.0,
@@ -368,6 +369,16 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
     );
     );
   }
   }
 
 
+  Future<void> updateTime(int newValidTill) async {
+    await _updateUrlSettings(
+      context,
+      {'validTill': newValidTill},
+    );
+    if(mounted) {
+      setState(() {});
+    }
+  }
+
   // _showDateTimePicker return null if user doesn't select date-time
   // _showDateTimePicker return null if user doesn't select date-time
   Future<int?> _showDateTimePicker() async {
   Future<int?> _showDateTimePicker() async {
     final dateResult = await DatePicker.showDatePicker(
     final dateResult = await DatePicker.showDatePicker(