mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-17 07:35:13 +00:00
refactor: Remove copy dialog before opening links
This can now be done by just selecting text
This commit is contained in:
parent
59de9d299d
commit
e6e3589f1f
2 changed files with 17 additions and 35 deletions
|
@ -141,7 +141,11 @@ class HtmlMessage extends StatelessWidget {
|
||||||
const ImageExtension(),
|
const ImageExtension(),
|
||||||
FontColorExtension(),
|
FontColorExtension(),
|
||||||
],
|
],
|
||||||
onLinkTap: (url, _, __) => UrlLauncher(context, url).launchUrl(),
|
onLinkTap: (url, _, element) => UrlLauncher(
|
||||||
|
context,
|
||||||
|
url,
|
||||||
|
element?.text,
|
||||||
|
).launchUrl(),
|
||||||
onlyRenderTheseTags: const {
|
onlyRenderTheseTags: const {
|
||||||
...allowedHtmlTags,
|
...allowedHtmlTags,
|
||||||
// Needed to make it work properly
|
// Needed to make it work properly
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:collection/collection.dart' show IterableExtension;
|
import 'package:collection/collection.dart' show IterableExtension;
|
||||||
|
@ -19,9 +18,10 @@ import 'platform_infos.dart';
|
||||||
|
|
||||||
class UrlLauncher {
|
class UrlLauncher {
|
||||||
final String? url;
|
final String? url;
|
||||||
|
final String? name;
|
||||||
final BuildContext context;
|
final BuildContext context;
|
||||||
|
|
||||||
const UrlLauncher(this.context, this.url);
|
const UrlLauncher(this.context, this.url, [this.name]);
|
||||||
|
|
||||||
void launchUrl() async {
|
void launchUrl() async {
|
||||||
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
|
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
|
||||||
|
@ -38,34 +38,17 @@ class UrlLauncher {
|
||||||
);
|
);
|
||||||
return;
|
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)) {
|
if (!{'https', 'http'}.contains(uri.scheme)) {
|
||||||
// just launch non-https / non-http uris directly
|
// just launch non-https / non-http uris directly
|
||||||
|
@ -241,8 +224,3 @@ class UrlLauncher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum _LaunchUrlResponse {
|
|
||||||
launch,
|
|
||||||
copy,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue