From 504335ed15fff7bfa21a8c94319eb52d841f6883 Mon Sep 17 00:00:00 2001 From: Adil Hanney Date: Sun, 12 Mar 2023 09:16:38 +0000 Subject: [PATCH] Create struct for text links --- .../widgets/toolbar/link_style_button.dart | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/src/widgets/toolbar/link_style_button.dart b/lib/src/widgets/toolbar/link_style_button.dart index d7119e02..b71d8ec2 100644 --- a/lib/src/widgets/toolbar/link_style_button.dart +++ b/lib/src/widgets/toolbar/link_style_button.dart @@ -85,7 +85,7 @@ class _LinkStyleButtonState extends State { } void _openLinkDialog(BuildContext context) { - showDialog( + showDialog<_TextLink>( context: context, builder: (ctx) { final link = _getLinkAttributeValue(); @@ -121,11 +121,7 @@ class _LinkStyleButtonState extends State { ?.value; } - void _linkSubmitted(dynamic value) { - // text.isNotEmpty && link.isNotEmpty - final String text = (value as Tuple2).item1; - final String link = value.item2.trim(); - + void _linkSubmitted(_TextLink value) { var index = widget.controller.selection.start; var length = widget.controller.selection.end - index; if (_getLinkAttributeValue() != null) { @@ -137,8 +133,9 @@ class _LinkStyleButtonState extends State { length = range.end - range.start; } } - widget.controller.replaceText(index, length, text, null); - widget.controller.formatText(index, text.length, LinkAttribute(link)); + widget.controller.replaceText(index, length, value.text, null); + widget.controller.formatText( + index, value.text.length, LinkAttribute(value.link)); } } @@ -239,6 +236,16 @@ class _LinkDialogState extends State<_LinkDialog> { } void _applyLink() { - Navigator.pop(context, Tuple2(_text.trim(), _link.trim())); + Navigator.pop(context, _TextLink(_text.trim(), _link.trim())); } } + +class _TextLink { + _TextLink( + this.text, + this.link, + ); + + final String text; + final String link; +}