Skip to content

Commit

Permalink
feat(#678): improve error page and mail
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Dec 27, 2023
1 parent 386653e commit 3edb2eb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
6 changes: 5 additions & 1 deletion app/lib/common/widgets/error_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class ErrorHandlerState extends State<ErrorHandler> {
}) async {
debugPrint(exception.toString());
debugPrintStack(stackTrace: stackTrace);
final errorString = exception.toString();
if (_needToHandleError(exception)) {
await widget.appRouter.push(ErrorRoute(error: exception.toString()));
final errorMailInfo = stackTrace != null
? '$errorString\n\n${stackTrace.toString()}'
: errorString;
await widget.appRouter.push(ErrorRoute(error: errorMailInfo));
}
}

Expand Down
7 changes: 6 additions & 1 deletion app/lib/common/widgets/full_width_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class FullWidthButton extends StatelessWidget {
this.action, {
super.key,
this.enabled = true,
this.secondaryColor = false,
});

final bool enabled;
final String text;
final void Function() action;
final bool secondaryColor;

@override
Widget build(BuildContext context) {
Expand All @@ -20,7 +22,10 @@ class FullWidthButton extends StatelessWidget {
onPressed: enabled ? action : null,
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(PharMeTheme.primaryColor),
MaterialStateProperty.all<Color>(secondaryColor
? PharMeTheme.secondaryColor
: PharMeTheme.primaryColor
),
),
child: Text(text, style: PharMeTheme.textTheme.bodyLarge),
),
Expand Down
13 changes: 13 additions & 0 deletions app/lib/common/widgets/link_text_span.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/gestures.dart';

import '../module.dart';

TextSpan linkTextSpan({required String text, required void Function() onTap}) =>
TextSpan(
text: text,
style: TextStyle(
color: PharMeTheme.secondaryColor,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()..onTap = onTap,
);
1 change: 1 addition & 0 deletions app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export 'full_width_button.dart';
export 'headings.dart';
export 'indicators.dart';
export 'lifecycle_observer.dart';
export 'link_text_span.dart';
export 'page_indicator_explanation.dart';
export 'page_scaffold.dart';
export 'pharme_logo_page.dart';
Expand Down
25 changes: 9 additions & 16 deletions app/lib/error/pages/error.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'dart:io';

import 'package:flutter/gestures.dart';

import '../../common/module.dart';

@RoutePage()
Expand Down Expand Up @@ -45,19 +43,12 @@ class ErrorPage extends StatelessWidget {
style: PharMeTheme.textTheme.bodyLarge,
children: [
TextSpan(text: context.l10n.error_uncaught_message_contact),
TextSpan(
linkTextSpan(
text: context.l10n.error_contact_link_text,
style: TextStyle(
color: PharMeTheme.secondaryColor,
decoration: TextDecoration.underline,
onTap: () => sendEmail(
subject: context.l10n.error_mail_subject,
body: context.l10n.error_mail_body(error),
),
recognizer: TapGestureRecognizer()..onTap =
() {
sendEmail(
subject: context.l10n.error_mail_subject,
body: context.l10n.error_mail_body(error),
);
},
),
TextSpan(
text: context.l10n.error_uncaught_message_after_link,
Expand All @@ -66,9 +57,11 @@ class ErrorPage extends StatelessWidget {
),
),
SizedBox(height: PharMeTheme.mediumSpace),
FullWidthButton(context.l10n.error_close_app, () async {
exit(0);
}),
FullWidthButton(
context.l10n.error_close_app,
() => exit(0),
secondaryColor: true,
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"error_uncaught_message_after_link": " if this problem persists.",
"error_close_app": "Close app",
"error_mail_subject": "Unknown PharMe Error Report",
"error_mail_body": "Error: {error} (please keep this line)\n\n<Please describe what happened right before the error occurred.>",
"error_mail_body": "Please describe what happened right before the error occurred: \n\n--- Please keep the following information, it will help us to pin down the error ---\n\n{error}",
"@error_mail_body": {
"placeholders": {
"error": {
Expand Down

0 comments on commit 3edb2eb

Please sign in to comment.