From faf424d5af1036a122fc1170fd52a4361c79ff14 Mon Sep 17 00:00:00 2001 From: miakh <2659269+miakh@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:56:07 +0100 Subject: [PATCH 1/3] delay fix --- lib/pages/AdministrationOccasion/UsersTab.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/AdministrationOccasion/UsersTab.dart b/lib/pages/AdministrationOccasion/UsersTab.dart index 749189eb..c2504138 100644 --- a/lib/pages/AdministrationOccasion/UsersTab.dart +++ b/lib/pages/AdministrationOccasion/UsersTab.dart @@ -204,6 +204,7 @@ class _UsersTabState extends State { print( "Retrying to invite user: ${user.data![Tb.occasion_users.data_email]}. Attempt: ${retryAttempts[user]}"); } + Future.delayed(Duration(milliseconds: 500)); } } }; From abcc0267db83adf7a58b980e5a2290f259fc2147 Mon Sep 17 00:00:00 2001 From: miakh <2659269+miakh@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:56:46 +0100 Subject: [PATCH 2/3] delay fix --- lib/pages/AdministrationOccasion/UsersTab.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pages/AdministrationOccasion/UsersTab.dart b/lib/pages/AdministrationOccasion/UsersTab.dart index c2504138..b10c5100 100644 --- a/lib/pages/AdministrationOccasion/UsersTab.dart +++ b/lib/pages/AdministrationOccasion/UsersTab.dart @@ -204,7 +204,7 @@ class _UsersTabState extends State { print( "Retrying to invite user: ${user.data![Tb.occasion_users.data_email]}. Attempt: ${retryAttempts[user]}"); } - Future.delayed(Duration(milliseconds: 500)); + await Future.delayed(Duration(milliseconds: 500)); } } }; From 29c78249f72912e7223f3199d9bda0b7e813fcd7 Mon Sep 17 00:00:00 2001 From: miakh <2659269+miakh@users.noreply.github.com> Date: Thu, 21 Nov 2024 17:51:12 +0100 Subject: [PATCH 3/3] cancellable progress dialog --- assets/translations/cs.json | 4 ++ assets/translations/de.json | 4 ++ assets/translations/en.json | 4 ++ assets/translations/pl.json | 4 ++ assets/translations/sk.json | 4 ++ assets/translations/uk.json | 4 ++ lib/services/DialogHelper.dart | 97 +++++++++++++++++++++++++++++----- 7 files changed, 107 insertions(+), 14 deletions(-) diff --git a/assets/translations/cs.json b/assets/translations/cs.json index ec64a49c..2be312e1 100644 --- a/assets/translations/cs.json +++ b/assets/translations/cs.json @@ -291,5 +291,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Nainstaluj si aplikaci {title}, aby ti mohly chodit notifikace, aby aplikace mohla fungovat i offline, a aby se dala spustit přes ikonku.", "Click here to sign in.": "Klikni sem pro přihlášení.", "Failed to invite {user}. Number of retries: ({retries}).": "Nepodařilo se pozvat {user}. Počet pokusů: ({retries}).", + "Processing...": "Zpracovává se...", + "The processing has finished with error.": "Zpracování skončilo chybou.", + "The processing has been cancelled.": "Zpracování bylo zrušeno.", + "The processing has completed successfully.": "Zpracování bylo úspěšně dokončeno.", "_": "_" } \ No newline at end of file diff --git a/assets/translations/de.json b/assets/translations/de.json index 5de561f3..65e1629a 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -291,5 +291,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Installiere {title}, um Benachrichtigungen zu erhalten, offline zu arbeiten und eine Schnellstart-Icon zu nutzen.", "Click here to sign in.": "Klicke hier, um dich anzumelden.", "Failed to invite {user}. Number of retries: ({retries}).": "Es konnte nicht eingeladen werden: {user}. Anzahl der Versuche: ({retries}).", + "Processing...": "Verarbeitung läuft...", + "The processing has finished with error.": "Die Verarbeitung wurde mit einem Fehler abgeschlossen.", + "The processing has been cancelled.": "Die Verarbeitung wurde abgebrochen.", + "The processing has completed successfully.": "Die Verarbeitung wurde erfolgreich abgeschlossen.", "_": "_" } diff --git a/assets/translations/en.json b/assets/translations/en.json index 322e3020..b539a1e5 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -291,5 +291,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Install {title} to get notifications, offline functionality, and a quick launch icon.", "Click here to sign in.": "Click here to sign in.", "Failed to invite {user}. Number of retries: ({retries}).": "Failed to invite {user}. Number of retries: ({retries}).", + "Processing...": "Processing...", + "The processing has finished with error.": "The processing has finished with error.", + "The processing has been cancelled.": "The processing has been cancelled.", + "The processing has completed successfully.": "The processing has completed successfully.", "_":"_" } \ No newline at end of file diff --git a/assets/translations/pl.json b/assets/translations/pl.json index 1598eb1a..67c8856b 100644 --- a/assets/translations/pl.json +++ b/assets/translations/pl.json @@ -290,5 +290,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Zainstaluj aplikację {title}, aby otrzymywać powiadomienia, korzystać z funkcji offline i mieć szybki dostęp przez ikonę.", "Click here to sign in.": "Kliknij tutaj, aby się zalogować.", "Failed to invite {user}. Number of retries: ({retries}).": "Nie udało się zaprosić {user}. Liczba prób: ({retries}).", + "Processing...": "Przetwarzanie...", + "The processing has finished with error.": "Przetwarzanie zakończyło się błędem.", + "The processing has been cancelled.": "Przetwarzanie zostało anulowane.", + "The processing has completed successfully.": "Przetwarzanie zakończyło się pomyślnie.", "_": "_" } \ No newline at end of file diff --git a/assets/translations/sk.json b/assets/translations/sk.json index ce23ee83..45fbe2f4 100644 --- a/assets/translations/sk.json +++ b/assets/translations/sk.json @@ -291,5 +291,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Nainštaluj si aplikáciu {title}, aby ti mohli chodiť notifikácie, aby aplikácia mohla fungovať aj offline, a aby sa dala spustiť cez ikonu.", "Click here to sign in.": "Klikni sem pre prihlásenie.", "Failed to invite {user}. Number of retries: ({retries}).": "Nepodarilo sa pozvať {user}. Počet pokusov: ({retries}).", + "Processing...": "Spracováva sa...", + "The processing has finished with error.": "Spracovanie skončilo chybou.", + "The processing has been cancelled.": "Spracovanie bolo zrušené.", + "The processing has completed successfully.": "Spracovanie bolo úspešne dokončené.", "_": "_" } \ No newline at end of file diff --git a/assets/translations/uk.json b/assets/translations/uk.json index bd8eecc9..b6159ba9 100644 --- a/assets/translations/uk.json +++ b/assets/translations/uk.json @@ -291,5 +291,9 @@ "Install {title} to get notifications, offline functionality, and a quick launch icon.": "Встанови {title}, щоб отримувати сповіщення, працювати офлайн і мати швидкий доступ через іконку.", "Click here to sign in.": "Натисни тут, щоб увійти.", "Failed to invite {user}. Number of retries: ({retries}).": "Не вдалося запросити {user}. Кількість спроб: ({retries}).", + "Processing...": "Обробка...", + "The processing has finished with error.": "Обробка завершилася з помилкою.", + "The processing has been cancelled.": "Обробку було скасовано.", + "The processing has completed successfully.": "Обробку успішно завершено.", "_": "_" } diff --git a/lib/services/DialogHelper.dart b/lib/services/DialogHelper.dart index 6f51cfad..e513b03e 100644 --- a/lib/services/DialogHelper.dart +++ b/lib/services/DialogHelper.dart @@ -9,6 +9,7 @@ import 'package:fstapp/appConfig.dart'; import 'package:flutter/material.dart'; import 'package:cross_file/cross_file.dart'; +import 'package:fstapp/themeConfig.dart'; import 'package:fstapp/widgets/PasswordField.dart'; import 'package:search_page/search_page.dart'; import 'package:select_dialog/select_dialog.dart'; @@ -316,6 +317,11 @@ class DialogHelper{ }) async { final completer = Completer(); final progressNotifier = ValueNotifier(0); + final isCancelled = ValueNotifier(false); // Track cancellation state + final statusMessage = ValueNotifier(""); // Track status message + final isStornoActive = ValueNotifier(true); // Track Storno button state + final isOkActive = ValueNotifier(false); // Track Ok button state + bool hasError = false; // Track if any error occurred // Show the dialog showDialog( @@ -333,17 +339,65 @@ class DialogHelper{ Text("${"Progress".tr()}: $progress/$total"), SizedBox(height: 20), LinearProgressIndicator(value: total > 0 ? progress / total : 0), - if (progress >= total) - ...[ - SizedBox(height: 20), - ElevatedButton( - onPressed: () { - Navigator.of(context).pop(); - completer.complete(); + SizedBox(height: 20), + ValueListenableBuilder( + valueListenable: statusMessage, + builder: (context, message, _) { + return Text( + message, + style: TextStyle( + color: hasError + ? ThemeConfig.redColor(context) + : ThemeConfig.blackColor(context), + ), + textAlign: TextAlign.center, + ); + }, + ), + SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.center, // Center the row + children: [ + ValueListenableBuilder( + valueListenable: isStornoActive, + builder: (context, isActive, _) { + return SizedBox( + width: 100, // Set equal width for both buttons + child: ElevatedButton( + onPressed: isActive + ? () { + isCancelled.value = true; // Mark as cancelled + isStornoActive.value = false; // Disable Storno + isOkActive.value = true; // Enable Ok button + statusMessage.value = + "The processing has been cancelled.".tr(); // Update status + } + : null, + child: Text("Storno".tr()), + ), + ); + }, + ), + SizedBox(width: 20), // Add space between buttons + ValueListenableBuilder( + valueListenable: isOkActive, + builder: (context, isActive, _) { + return SizedBox( + width: 100, // Set equal width for both buttons + child: ElevatedButton( + onPressed: isActive + ? () { + Navigator.of(context).pop(); + completer.complete(); + } + : null, + child: Text("Ok".tr()), + ), + ); }, - child: Text("Ok".tr()), ), ], + ), ], ), ); @@ -353,22 +407,37 @@ class DialogHelper{ ); // Execute futures sequentially - if (futures !=null && futures.isNotEmpty) { + if (futures != null && futures.isNotEmpty) { for (var future in futures) { + if (isCancelled.value) break; // Stop execution if cancelled try { + statusMessage.value = "Processing...".tr(); // Update processing message await future.call(); // Wait for each future to finish progressNotifier.value++; - if(delay!=null){ + if (delay != null) { await Future.delayed(delay); } } catch (e) { - ToastHelper.Show(context, e.toString(), severity: ToastSeverity.NotOk); + // On error: Stop further execution and display the error + statusMessage.value = "$e"; + isCancelled.value = true; // Stop further processing + isStornoActive.value = false; // Disable Storno button + isOkActive.value = true; // Enable Ok button + hasError = true; // Mark that an error occurred + break; } } + } + + // Mark actions as completed + isOkActive.value = true; // Enable Ok button after actions are completed + isStornoActive.value = false; // Disable Storno button whenever Ok is enabled + if (hasError) { + statusMessage.value = "The processing has finished with error.".tr(); + } else if (isCancelled.value) { + statusMessage.value = "The processing has been cancelled.".tr(); } else { - // Complete immediately if no futures are provided - completer.complete(); - Navigator.of(context).pop(); + statusMessage.value = "The processing has completed successfully.".tr(); } // Await the completer if not already completed