Skip to content

Commit

Permalink
feat(app): use Text widget for links (RichText not reacting to iOS te…
Browse files Browse the repository at this point in the history
…xt size change)
  • Loading branch information
tamslo committed Mar 1, 2024
1 parent f879aec commit 6c826f8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 54 deletions.
11 changes: 8 additions & 3 deletions app/lib/common/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Uri keycloakUrl([String slug = '']) =>

// Note that sending emails will not work on the iPhone Simulator since it does
// not have any email application installed.
String _mailContact = '[email protected]';
String contactEmailAddress = '[email protected]';
// Workaround according to https://pub.dev/packages/url_launcher#encoding-urls
String? _encodeQueryParameters(Map<String, String> params) {
return params.entries
Expand All @@ -24,7 +24,7 @@ Future<void> sendEmail({
await launchUrl(
Uri(
scheme: 'mailto',
path: _mailContact,
path: contactEmailAddress,
query: _encodeQueryParameters({
'subject': subject,
'body': body,
Expand All @@ -33,8 +33,13 @@ Future<void> sendEmail({
);
}

final geneticInformationUrl = Uri.https(
'medlineplus.gov',
'/genetics/understanding/',
);

Future<void> openFurtherGeneticInformation() async =>
launchUrl(Uri.https('medlineplus.gov', '/genetics/understanding/'));
launchUrl(geneticInformationUrl);

final cpicMaxCacheTime = Duration(days: 90);
const maxCachedDrugs = 10;
Expand Down
22 changes: 22 additions & 0 deletions app/lib/common/widgets/hyperlink.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '../module.dart';

class Hyperlink extends StatelessWidget {
const Hyperlink({ required this.text, required this.onTap });
final String text;
final void Function() onTap;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Text(
text,
style: TextStyle(
color: PharMeTheme.secondaryColor,
decoration: TextDecoration.underline,
decorationColor: PharMeTheme.secondaryColor,
),
),
);
}
}
13 changes: 0 additions & 13 deletions app/lib/common/widgets/link_text_span.dart

This file was deleted.

2 changes: 1 addition & 1 deletion app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export 'drug_search/filter_menu.dart';
export 'error_handler.dart';
export 'full_width_button.dart';
export 'headings.dart';
export 'hyperlink.dart';
export 'indicators.dart';
export 'lifecycle_observer.dart';
export 'link_text_span.dart';
export 'page_description.dart';
export 'page_indicator_explanation.dart';
export 'page_scaffold.dart';
Expand Down
27 changes: 11 additions & 16 deletions app/lib/error/pages/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class ErrorPage extends StatelessWidget {
child: PharMeLogoPage(
greyscale: true,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
context.l10n.error_title,
style: PharMeTheme.textTheme.headlineMedium,
textAlign: TextAlign.center,
),
SizedBox(height: PharMeTheme.mediumSpace),
RichText(
Expand All @@ -37,23 +39,16 @@ class ErrorPage extends StatelessWidget {
),
),
SizedBox(height: PharMeTheme.mediumSpace),
RichText(
Text(
context.l10n.error_uncaught_message_contact,
style: PharMeTheme.textTheme.bodyLarge,
textAlign: TextAlign.center,
text: TextSpan(
style: PharMeTheme.textTheme.bodyLarge,
children: [
TextSpan(text: context.l10n.error_uncaught_message_contact),
linkTextSpan(
text: context.l10n.error_contact_link_text,
onTap: () => sendEmail(
subject: context.l10n.error_mail_subject,
body: context.l10n.error_mail_body(error),
),
),
TextSpan(
text: context.l10n.error_uncaught_message_after_link,
),
],
),
Hyperlink(
text: contactEmailAddress,
onTap: () => sendEmail(
subject: context.l10n.error_mail_subject,
body: context.l10n.error_mail_body(error),
),
),
SizedBox(height: PharMeTheme.mediumSpace),
Expand Down
21 changes: 10 additions & 11 deletions app/lib/faq/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,20 @@ final Map<String, List<Question>> faqList = {
),
WidgetAnswerQuestion(
question: 'Where can I find out more about genetics in general?',
answer: RichText(text: TextSpan(
// context.l10n.genetic_information_text_part_1
text: 'If you would like to learn more about genetics, we recommend ',
style: PharMeTheme.textTheme.titleMedium,
answer: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
linkTextSpan(
text: 'MedlinePlus', // context.l10n.genetic_information_source
onTap: openFurtherGeneticInformation,
Text(
'To learn more about genetics, we recommend MedlinePlus,'
' a service of the National Library of Medicine:'
),
TextSpan(
// context.l10n.genetic_information_text_part_2
text: ', a service of the National Library of Medicine.',
SizedBox(height: PharMeTheme.smallSpace * 0.5),
Hyperlink(
text: geneticInformationUrl.toString(),
onTap: openFurtherGeneticInformation,
),
],
)),
),
),
TextAnswerQuestion(
question: 'Which drugs are affected?',
Expand Down
9 changes: 1 addition & 8 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"error_title": "Something went wrong",
"error_uncaught_message_first_part": "PharMe has encountered an unknown error. ",
"error_uncaught_message_bold_part": "Please close the app and open it again.",
"error_uncaught_message_contact": "The error has been logged for our technical staff; however, please ",
"error_contact_link_text": "contact us",
"error_uncaught_message_after_link": " if this problem persists.",
"error_uncaught_message_contact": "The error has been logged for our technical staff; however, if this problem persists, please contact us:",
"error_close_app": "Close app",
"error_mail_subject": "[ACTION REQUIRED] Unknown Error Report",
"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}",
Expand All @@ -27,10 +25,6 @@
"auth_sign_in": "Get data",
"auth_success": "Successfully imported data",

"genetic_information_text_part_1": "If you would like to learn more about genetics, we recommend ",
"genetic_information_text_part_2": ", a service of the National Library of Medicine.",
"genetic_information_source": "MedlinePlus",

"drug_selection_header": "Currently taken drugs",
"drug_selection_onboarding_description": "Please update which drugs you are currently taking below. You can always change the status for a drug later on a drug page or in the settings.",
"drug_selection_settings_description": "Review your currently taken drugs below.",
Expand All @@ -46,7 +40,6 @@
"update_warning_title": "Updated guidelines",
"update_warning_body": "The guidelines for gene-drug interactions were updated. Please review your information, especially for drugs you are currently taking.",


"faq_contact_us": "Do you have unanswered questions or feedback? Contact us",

"general_continue": "Continue",
Expand Down
4 changes: 2 additions & 2 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ List<InlineSpan> _buildWarningLevelIndicator(
child: Icon(
warningLevel.icon,
color: warningLevel.textColor,
size: pageDescriptionTextStyle!.fontSize,
size: PharMeTheme.textTheme.bodyMedium!.fontSize,
),
),
WidgetSpan(
Expand All @@ -182,7 +182,7 @@ List<InlineSpan> _buildWarningLevelIndicator(
),
TextSpan(
text: text,
style: pageDescriptionTextStyle!.copyWith(color: warningLevel.textColor)
style: PharMeTheme.textTheme.bodyMedium!.copyWith(color: warningLevel.textColor)
),
];
}

0 comments on commit 6c826f8

Please sign in to comment.