Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved error message for scanner page's upload button #281

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/features/document_scan/view/scanner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class _ScannerPageState extends State<ScannerPage>
);
},
disabled: state.scans.isEmpty,
disabledReason: S.of(context)!.noDocumentsScanned,
child: TextButton.icon(
label: Text(S.of(context)!.upload),
style: TextButton.styleFrom(
Expand Down
17 changes: 15 additions & 2 deletions lib/helpers/connectivity_aware_action_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -36,20 +37,32 @@ class ConnectivityAwareActionWrapper extends StatelessWidget {
this.offlineBuilder = ConnectivityAwareActionWrapper.disabledBuilder,
required this.child,
this.disabled = false,
this.disabledReason
});

@override
Widget build(BuildContext context) {
return StreamBuilder<bool>(
stream: context.read<ConnectivityStatusService>().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),
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/intl_ca.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding all translations: Did you add the new strings to the .arb files directly or did you create them in crowdin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them directly

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think it would make more sense to not show a message when the button is disabled due to the current app state (not connectivity state), i.e. don't show a snackbar at all. Otherwise we would need a reason why the button is disabled. It should be evident to the user that the upload button is disabled because there is nothing to upload. So maybe remove the translations and the disabledReason property. Only show the "You're offline" snackbar when the user is offline and therefore the button is disabled. If disabled is true but the user is online, don't show anything.

"noDocumentsScanned": "You have not scanned any documents yet."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}