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

feat: Better support error when saving the picture locally #4305

Merged
merged 5 commits into from
Jul 17, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_responsive.dart';
import 'package:smooth_app/helpers/app_helper.dart';

/// Custom Dialog to use in the app
///
Expand Down Expand Up @@ -466,3 +469,68 @@ class _SmoothActionFlatButton extends StatelessWidget {
);
}
}

/// A custom dialog where you only have to pass a [title] and a [message].
/// By default an "OK" button will be show., but you can override it by passing
/// a [positiveAction] and/or [negativeAction]
class SmoothSimpleErrorAlertDialog extends StatelessWidget {
const SmoothSimpleErrorAlertDialog({
required this.title,
required this.message,
this.positiveAction,
this.negativeAction,
this.actionsAxis,
this.actionsOrder,
this.contentPadding,
});

final String title;
final String message;
final SmoothActionButton? positiveAction;
final SmoothActionButton? negativeAction;
final Axis? actionsAxis;
final SmoothButtonsBarOrder? actionsOrder;
final EdgeInsetsDirectional? contentPadding;

@override
Widget build(BuildContext context) {
final Widget content = Column(
children: <Widget>[
SvgPicture.asset(
'assets/misc/error.svg',
width: MINIMUM_TOUCH_SIZE * 2,
package: AppHelper.APP_PACKAGE,
),
const SizedBox(height: MEDIUM_SPACE),
Text(
title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: LARGE_SPACE),
Text(
message,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(height: 1.3),
),
],
);

SmoothActionButton? positiveButton = positiveAction;
if (positiveAction == null && negativeAction == null) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
positiveButton = SmoothActionButton(
text: appLocalizations.okay,
onPressed: () => Navigator.of(context).maybePop(),
);
}

return SmoothAlertDialog(
body: content,
positiveAction: positiveButton,
negativeAction: negativeAction,
actionsOrder: actionsOrder,
contentPadding: contentPadding,
);
}
}
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ class AnalyticsHelper {
}
}

static void sendException(dynamic throwable, {dynamic stackTrace}) {
Sentry.captureException(throwable, stackTrace: stackTrace);
}

static String? get matomoVisitorId => MatomoTracker.instance.visitor.id;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@
"@crop_page_action_local": {
"description": "Action being performed on the crop page"
},
"crop_page_action_local_failed_title": "Oops… there's something with your photo!",
"@crop_page_action_local_title": {
"description": "The save of the picture locally failed - error dialog message"
},
"crop_page_action_local_failed_message": "We are unable to process the image locally, before sending it to our server. Please try again later or contact-us if the issue persists.",
"@crop_page_action_local_message": {
"description": "The save of the picture locally failed - error dialog message"
},
"crop_page_too_small_image_title": "The image is too small!",
"@crop_page_too_small_image_title": {
"description": "Title of a dialog warning the user that the image is too small for upload"
Expand Down
26 changes: 25 additions & 1 deletion packages/smooth_app/lib/pages/crop_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/loading_dialog.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/database_helper.dart';
import 'package:smooth_app/helpers/image_compute_container.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
Expand Down Expand Up @@ -239,7 +240,15 @@ class _CropPageState extends State<CropPage> {
maxSize: _screenSize.longestSide,
);
setState(() => _progress = appLocalizations.crop_page_action_local);
await saveBmp(file: result, source: cropped);

try {
await saveBmp(file: result, source: cropped)
.timeout(const Duration(seconds: 10));
} catch (e, trace) {
AnalyticsHelper.sendException(e, stackTrace: trace);
rethrow;
}

return result;
}

Expand Down Expand Up @@ -387,6 +396,7 @@ class _CropPageState extends State<CropPage> {
return true;
}
} catch (e) {
_showErrorDialog();
return false;
} finally {
_progress = null;
Expand Down Expand Up @@ -493,6 +503,20 @@ class _CropPageState extends State<CropPage> {
return false;
}
}

Future<void> _showErrorDialog() {
final AppLocalizations appLocalizations = AppLocalizations.of(context);

return showDialog<void>(
context: context,
builder: (BuildContext context) {
return SmoothSimpleErrorAlertDialog(
title: appLocalizations.crop_page_action_local_failed_title,
message: appLocalizations.crop_page_action_local_failed_message,
);
},
);
}
}

/// Standard icon button for this page.
Expand Down