From 3edb2eb424fbe58a75c763127b4c685493564e8d Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Thu, 28 Dec 2023 00:04:47 +0100 Subject: [PATCH] feat(#678): improve error page and mail --- app/lib/common/widgets/error_handler.dart | 6 ++++- app/lib/common/widgets/full_width_button.dart | 7 +++++- app/lib/common/widgets/link_text_span.dart | 13 ++++++++++ app/lib/common/widgets/module.dart | 1 + app/lib/error/pages/error.dart | 25 +++++++------------ app/lib/l10n/app_en.arb | 2 +- 6 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 app/lib/common/widgets/link_text_span.dart diff --git a/app/lib/common/widgets/error_handler.dart b/app/lib/common/widgets/error_handler.dart index 588f77c7..4dc1c15d 100644 --- a/app/lib/common/widgets/error_handler.dart +++ b/app/lib/common/widgets/error_handler.dart @@ -34,8 +34,12 @@ class ErrorHandlerState extends State { }) 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)); } } diff --git a/app/lib/common/widgets/full_width_button.dart b/app/lib/common/widgets/full_width_button.dart index 5e73b9dc..2d8f07b3 100644 --- a/app/lib/common/widgets/full_width_button.dart +++ b/app/lib/common/widgets/full_width_button.dart @@ -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) { @@ -20,7 +22,10 @@ class FullWidthButton extends StatelessWidget { onPressed: enabled ? action : null, style: ButtonStyle( backgroundColor: - MaterialStateProperty.all(PharMeTheme.primaryColor), + MaterialStateProperty.all(secondaryColor + ? PharMeTheme.secondaryColor + : PharMeTheme.primaryColor + ), ), child: Text(text, style: PharMeTheme.textTheme.bodyLarge), ), diff --git a/app/lib/common/widgets/link_text_span.dart b/app/lib/common/widgets/link_text_span.dart new file mode 100644 index 00000000..e66ebe9e --- /dev/null +++ b/app/lib/common/widgets/link_text_span.dart @@ -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, + ); \ No newline at end of file diff --git a/app/lib/common/widgets/module.dart b/app/lib/common/widgets/module.dart index ee92ae42..ceeaccf1 100644 --- a/app/lib/common/widgets/module.dart +++ b/app/lib/common/widgets/module.dart @@ -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'; diff --git a/app/lib/error/pages/error.dart b/app/lib/error/pages/error.dart index 0fbf221e..18bf3655 100644 --- a/app/lib/error/pages/error.dart +++ b/app/lib/error/pages/error.dart @@ -1,7 +1,5 @@ import 'dart:io'; -import 'package:flutter/gestures.dart'; - import '../../common/module.dart'; @RoutePage() @@ -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, @@ -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, + ), ], ), ), diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index 15826fe5..08e51520 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -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", + "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": {