safeLaunchUri function

Future<void> safeLaunchUri(
  1. Uri uri, {
  2. LaunchMode mode = LaunchMode.platformDefault,
  3. bool showError = false,
  4. String? defaultErrorText,
})

Implementation

Future<void> safeLaunchUri(Uri uri,
    {LaunchMode mode = LaunchMode.platformDefault,
    bool showError = false,
    String? defaultErrorText}) async {
  try {
    await launchUrl(uri, mode: mode);
  } on Exception catch (error) {
    if (showError) {
      if (kDebugMode) {
        App.dialog.showError(error);
      } else {
        App.dialog.showError(defaultErrorText ?? error);
      }
    }
  }
}