diff --git a/lib/pages/chat/events/html_message.dart b/lib/pages/chat/events/html_message.dart
index b050409b..3a47121f 100644
--- a/lib/pages/chat/events/html_message.dart
+++ b/lib/pages/chat/events/html_message.dart
@@ -141,7 +141,11 @@ class HtmlMessage extends StatelessWidget {
const ImageExtension(),
FontColorExtension(),
],
- onLinkTap: (url, _, __) => UrlLauncher(context, url).launchUrl(),
+ onLinkTap: (url, _, element) => UrlLauncher(
+ context,
+ url,
+ element?.text,
+ ).launchUrl(),
onlyRenderTheseTags: const {
...allowedHtmlTags,
// Needed to make it work properly
diff --git a/lib/utils/url_launcher.dart b/lib/utils/url_launcher.dart
index d6c86838..f7bb72fd 100644
--- a/lib/utils/url_launcher.dart
+++ b/lib/utils/url_launcher.dart
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart' show IterableExtension;
@@ -19,9 +18,10 @@ import 'platform_infos.dart';
class UrlLauncher {
final String? url;
+ final String? name;
final BuildContext context;
- const UrlLauncher(this.context, this.url);
+ const UrlLauncher(this.context, this.url, [this.name]);
void launchUrl() async {
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
@@ -38,34 +38,17 @@ class UrlLauncher {
);
return;
}
- final consent = await showModalActionSheet<_LaunchUrlResponse>(
- context: context,
- title: url,
- style: AdaptiveStyle.material,
- actions: [
- SheetAction(
- key: _LaunchUrlResponse.copy,
- icon: Icons.copy_outlined,
- label: L10n.of(context)!.copy,
- ),
- SheetAction(
- key: _LaunchUrlResponse.launch,
- icon: Icons.launch_outlined,
- label: L10n.of(context)!.openLinkInBrowser,
- ),
- ],
- );
- if (consent == _LaunchUrlResponse.copy) {
- await Clipboard.setData(ClipboardData(text: uri.toString()));
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text(L10n.of(context)!.copiedToClipboard),
- ),
- );
- return;
- }
- if (consent != _LaunchUrlResponse.launch) return;
+ if (url != name) {
+ final consent = await showOkCancelAlertDialog(
+ context: context,
+ title: L10n.of(context)!.openLinkInBrowser,
+ message: url,
+ okLabel: L10n.of(context)!.yes,
+ cancelLabel: L10n.of(context)!.cancel,
+ );
+ if (consent != OkCancelResult.ok) return;
+ }
if (!{'https', 'http'}.contains(uri.scheme)) {
// just launch non-https / non-http uris directly
@@ -241,8 +224,3 @@ class UrlLauncher {
}
}
}
-
-enum _LaunchUrlResponse {
- launch,
- copy,
-}