feat: support customizing link button (#1048)

This commit is contained in:
Lucas 2025-03-03 16:53:25 +08:00 • committed by GitHub
commit b2672f297b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 7 additions and 5 deletions

View file

@ -38,7 +38,7 @@ KeyEventResult _openInlineLink(
}
if (linkText != null) {
safeLaunchUrl(linkText);
editorLaunchUrl(linkText);
}
return KeyEventResult.handled;

View file

@ -37,7 +37,7 @@ TextSpan defaultTextSpanDecoratorForAttribute(
HardwareKeyboard.instance.isControlPressed ||
HardwareKeyboard.instance.isMetaPressed) {
tapCount = 0;
safeLaunchUrl(href);
editorLaunchUrl(href);
return;
}
timer = Timer(const Duration(milliseconds: 200), () {

View file

@ -92,7 +92,7 @@ void showLinkMenu(
linkText: linkText,
editorState: editorState,
onOpenLink: () async {
await safeLaunchUrl(linkText);
await editorLaunchUrl(linkText);
},
onSubmitted: (text) async {
if (isUri(text)) {

View file

@ -12,3 +12,5 @@ Future<bool> safeLaunchUrl(String? href) async {
}
return Future.value(true);
}
Future<bool> Function(String? href) editorLaunchUrl = safeLaunchUrl;

View file

@ -4,7 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
test('safeLaunchUrl without href and scheme', () async {
const href = null;
final result = await safeLaunchUrl(href);
final result = await editorLaunchUrl(href);
expect(result, false);
});
}

View file

@ -27,7 +27,7 @@ void main() {
await widgetTester.pumpAndSettle();
// test the method only
expect(() => safeLaunchUrl(address), returnsNormally);
expect(() => editorLaunchUrl(address), returnsNormally);
},
);
testWidgets(