mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-02 17:29:34 +01:00
feat: add button to copy url in open dialog
Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
parent
3820d4264a
commit
d381705cdd
@ -1,4 +1,5 @@
|
|||||||
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;
|
||||||
@ -37,14 +38,36 @@ class UrlLauncher {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final consent = await showOkCancelAlertDialog(
|
final consent = await showConfirmationDialog(
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context)!.openLinkInBrowser,
|
title: L10n.of(context)!.openLinkInBrowser,
|
||||||
message: url,
|
message: url,
|
||||||
okLabel: L10n.of(context)!.ok,
|
actions: [
|
||||||
cancelLabel: L10n.of(context)!.cancel,
|
AlertDialogAction(
|
||||||
|
key: null,
|
||||||
|
label: L10n.of(context)!.cancel,
|
||||||
|
),
|
||||||
|
AlertDialogAction(
|
||||||
|
key: _LaunchUrlResponse.copy,
|
||||||
|
label: L10n.of(context)!.copy,
|
||||||
|
),
|
||||||
|
AlertDialogAction(
|
||||||
|
key: _LaunchUrlResponse.launch,
|
||||||
|
label: L10n.of(context)!.ok,
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
if (consent != OkCancelResult.ok) return;
|
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 (!{'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
|
||||||
@ -215,3 +238,8 @@ class UrlLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum _LaunchUrlResponse {
|
||||||
|
launch,
|
||||||
|
copy,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user