From ea335c82d4d49135cc1e2dfb37e0bdfd1c768e95 Mon Sep 17 00:00:00 2001 From: Patrick <24683548+pohuing@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:51:37 +0200 Subject: [PATCH] Add improved error message for scanner page's upload button --- .../document_scan/view/scanner_page.dart | 1 + .../connectivity_aware_action_wrapper.dart | 17 +++++++++++++++-- lib/l10n/intl_ca.arb | 3 ++- lib/l10n/intl_cs.arb | 3 ++- lib/l10n/intl_de.arb | 3 ++- lib/l10n/intl_en.arb | 3 ++- lib/l10n/intl_es.arb | 3 ++- lib/l10n/intl_fr.arb | 3 ++- lib/l10n/intl_pl.arb | 3 ++- lib/l10n/intl_ru.arb | 3 ++- lib/l10n/intl_tr.arb | 3 ++- 11 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/features/document_scan/view/scanner_page.dart b/lib/features/document_scan/view/scanner_page.dart index d44f6239..748a8c4a 100644 --- a/lib/features/document_scan/view/scanner_page.dart +++ b/lib/features/document_scan/view/scanner_page.dart @@ -154,6 +154,7 @@ class _ScannerPageState extends State ); }, disabled: state.scans.isEmpty, + disabledReason: S.of(context)!.noDocumentsScanned, child: TextButton.icon( label: Text(S.of(context)!.upload), style: TextButton.styleFrom( diff --git a/lib/helpers/connectivity_aware_action_wrapper.dart b/lib/helpers/connectivity_aware_action_wrapper.dart index f69e922c..3ad03976 100644 --- a/lib/helpers/connectivity_aware_action_wrapper.dart +++ b/lib/helpers/connectivity_aware_action_wrapper.dart @@ -13,6 +13,7 @@ class ConnectivityAwareActionWrapper extends StatelessWidget { final OfflineBuilder offlineBuilder; final Widget child; final bool disabled; + final String? disabledReason; static Widget disabledBuilder(BuildContext context, Widget? child) { return ColorFiltered( @@ -36,6 +37,7 @@ class ConnectivityAwareActionWrapper extends StatelessWidget { this.offlineBuilder = ConnectivityAwareActionWrapper.disabledBuilder, required this.child, this.disabled = false, + this.disabledReason }); @override @@ -43,13 +45,24 @@ class ConnectivityAwareActionWrapper extends StatelessWidget { return StreamBuilder( stream: context.read().connectivityChanges(), builder: (context, snapshot) { + final isOffline =!snapshot.hasData || snapshot.data == false; final disableButton = - !snapshot.hasData || snapshot.data == false || disabled; + isOffline || disabled; if (disableButton) { return GestureDetector( onTap: () { HapticFeedback.heavyImpact(); - showSnackBar(context, S.of(context)!.youAreCurrentlyOffline); + var errorString = ""; + if (isOffline) { + errorString = S.of(context)!.youAreCurrentlyOffline; + if (disabled) { + errorString = errorString + '\n'; + } + } + if (disabled && disabledReason != null) { + errorString = errorString + disabledReason!; + } + showSnackBar(context, errorString); }, child: AbsorbPointer( child: offlineBuilder(context, child), diff --git a/lib/l10n/intl_ca.arb b/lib/l10n/intl_ca.arb index 2a2c013e..4f460e15 100644 --- a/lib/l10n/intl_ca.arb +++ b/lib/l10n/intl_ca.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_cs.arb b/lib/l10n/intl_cs.arb index 32676157..12fecfd2 100644 --- a/lib/l10n/intl_cs.arb +++ b/lib/l10n/intl_cs.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index 6438a81e..bfb1f05f 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "Du hast noch keine Dokumente gescannt." } \ No newline at end of file diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 37a00a89..83b0e432 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index daa10e50..02236ecd 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 8d81cb7b..34fd3ac3 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_pl.arb b/lib/l10n/intl_pl.arb index 4a6fa142..622ed4cc 100644 --- a/lib/l10n/intl_pl.arb +++ b/lib/l10n/intl_pl.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 42535d29..57e762b9 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file diff --git a/lib/l10n/intl_tr.arb b/lib/l10n/intl_tr.arb index a1c0e30a..f5727ecd 100644 --- a/lib/l10n/intl_tr.arb +++ b/lib/l10n/intl_tr.arb @@ -1001,5 +1001,6 @@ "@discardChangesWarning": { "description": "Warning message shown when the user tries to close a route without saving the changes." }, - "changelog": "Changelog" + "changelog": "Changelog", + "noDocumentsScanned": "You have not scanned any documents yet." } \ No newline at end of file