refactor: Remove copy dialog before opening links

This can now be done by just selecting text
This commit is contained in:
krille-chan 2023-11-12 08:21:53 +01:00
parent 59de9d299d
commit e6e3589f1f
No known key found for this signature in database
2 changed files with 17 additions and 35 deletions

View file

@ -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

View file

@ -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,
}