Skip to content

Commit

Permalink
fix: When there is no browser, the app shouldn't crash (#4729)
Browse files Browse the repository at this point in the history
* When there is no browser, we should inform the user that a link can't be opened

* Fix build error
  • Loading branch information
g123k authored Oct 25, 2023
1 parent 06da6ea commit e32f566
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 16 additions & 1 deletion packages/smooth_app/lib/generic_lib/smooth_html_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_selectable_text/fwfh_selectable_text.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
Expand All @@ -20,7 +21,21 @@ class SmoothHtmlWidget extends StatelessWidget {
htmlString,
textStyle: textStyle,
onTapUrl: (String url) async {
await LaunchUrlHelper.launchURL(url, false);
try {
await LaunchUrlHelper.launchURL(url, false);
} catch (_) {
if (context.mounted) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);

ScaffoldMessenger.maybeOf(context)?.showSnackBar(
SnackBar(
content: Text(appLocalizations.link_cant_be_opened),
),
);
}
}

return true;
},
factoryBuilder: () =>
Expand Down
6 changes: 5 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2475,5 +2475,9 @@
"hunger_games_loading_line1": "Please let us a few seconds…",
"hunger_games_loading_line2": "We're downloading the questions!",
"hunger_games_error_label": "Argh! Something went wrong… and we couldn't load the questions.",
"hunger_games_error_retry_button": "Let's retry!"
"hunger_games_error_retry_button": "Let's retry!",
"link_cant_be_opened": "This link can't be opened on your device. Please check that you have a browser installed.",
"@link_cant_be_opened": {
"description": "An error may happen if the device doesn't have a browser installed."
}
}

0 comments on commit e32f566

Please sign in to comment.