1- import 'package:flutter/material.dart' ;
2-
3- import '../../common/utils/link_validator.dart' ;
4- import '../../editor/widgets/link.dart' ;
5- import '../../l10n/extensions/localizations_ext.dart' ;
6- import '../../rules/insert.dart' ;
7- import '../base_button/base_value_button.dart' ;
8-
9- import '../config/buttons/link_style_options.dart' ;
10- import '../structs/link_dialog_action.dart' ;
11- import '../theme/quill_dialog_theme.dart' ;
12- import 'quill_icon_button.dart' ;
13-
14- typedef QuillToolbarLinkStyleBaseButton = QuillToolbarBaseButton <
15- QuillToolbarLinkStyleButtonOptions ,
16- QuillToolbarLinkStyleButtonExtraOptions >;
17-
18- typedef QuillToolbarLinkStyleBaseButtonState <
19- W extends QuillToolbarLinkStyleBaseButton >
20- = QuillToolbarCommonButtonState <W , QuillToolbarLinkStyleButtonOptions ,
21- QuillToolbarLinkStyleButtonExtraOptions >;
22-
23- class QuillToolbarLinkStyleButton extends QuillToolbarLinkStyleBaseButton {
24- const QuillToolbarLinkStyleButton ({
25- required super .controller,
26- super .options = const QuillToolbarLinkStyleButtonOptions (),
27-
28- /// Shares common options between all buttons, prefer the [options]
29- /// over the [baseOptions] .
30- super .baseOptions,
31- super .key,
32- });
33-
34- @override
35- QuillToolbarLinkStyleButtonState createState () =>
36- QuillToolbarLinkStyleButtonState ();
37- }
38-
39- class QuillToolbarLinkStyleButtonState
40- extends QuillToolbarLinkStyleBaseButtonState {
41- @override
42- String get defaultTooltip => context.loc.insertURL;
43-
44- void _didChangeSelection () {
45- setState (() {});
46- }
47-
48- @override
49- void initState () {
50- super .initState ();
51- controller.addListener (_didChangeSelection);
52- }
53-
54- @override
55- void didUpdateWidget (covariant QuillToolbarLinkStyleButton oldWidget) {
56- super .didUpdateWidget (oldWidget);
57- if (oldWidget.controller != controller) {
58- oldWidget.controller.removeListener (_didChangeSelection);
59- controller.addListener (_didChangeSelection);
60- }
61- }
62-
63- @override
64- void dispose () {
65- super .dispose ();
66- controller.removeListener (_didChangeSelection);
67- }
68-
69- @override
70- IconData get defaultIconData => Icons .link;
71-
72- @override
73- Widget build (BuildContext context) {
74- final isToggled = QuillTextLink .isSelected (controller);
75-
76- final childBuilder = this .childBuilder;
77- if (childBuilder != null ) {
78- return childBuilder (
79- options,
80- QuillToolbarLinkStyleButtonExtraOptions (
81- context: context,
82- controller: controller,
83- onPressed: () {
84- _openLinkDialog (context);
85- afterButtonPressed? .call ();
86- },
87- ),
88- );
89- }
90- return QuillToolbarIconButton (
91- tooltip: tooltip,
92- icon: Icon (
93- iconData,
94- size: iconSize * iconButtonFactor,
95- ),
96- isSelected: isToggled,
97- onPressed: () => _openLinkDialog (context),
98- afterPressed: afterButtonPressed,
99- iconTheme: iconTheme,
100- );
101- }
1+ @internal
2+ @visibleForTesting
3+ library ;
1024
103- Future < void > _openLinkDialog ( BuildContext context) async {
104- final initialTextLink = QuillTextLink . prepare (widget.controller) ;
5+ import 'package:flutter/material.dart' ;
6+ import 'package:meta/meta.dart' ;
1057
106- final textLink = await showDialog <QuillTextLink >(
107- context: context,
108- builder: (_) {
109- return _LinkDialog (
110- validateLink: options.validateLink,
111- // ignore: deprecated_member_use_from_same_package
112- legacyLinkRegExp: options.linkRegExp,
113- dialogTheme: options.dialogTheme,
114- text: initialTextLink.text,
115- link: initialTextLink.link,
116- action: options.linkDialogAction,
117- );
118- },
119- );
120- if (textLink != null ) {
121- textLink.submit (widget.controller);
122- }
123- }
124- }
8+ import '../../../common/utils/link_validator.dart' ;
9+ import '../../../editor/widgets/link.dart' ;
10+ import '../../../l10n/extensions/localizations_ext.dart' ;
11+ import '../../../rules/insert.dart' ;
12+ import '../../structs/link_dialog_action.dart' ;
13+ import '../../theme/quill_dialog_theme.dart' ;
12514
126- class _LinkDialog extends StatefulWidget {
127- const _LinkDialog ({
15+ class LinkDialog extends StatefulWidget {
16+ const LinkDialog ({
12817 required this .validateLink,
18+ super .key,
12919 this .dialogTheme,
13020 this .link,
13121 this .text,
@@ -141,10 +31,10 @@ class _LinkDialog extends StatefulWidget {
14131 final LinkDialogAction ? action;
14232
14333 @override
144- _LinkDialogState createState () => _LinkDialogState ();
34+ LinkDialogState createState () => LinkDialogState ();
14535}
14636
147- class _LinkDialogState extends State <_LinkDialog > {
37+ class LinkDialogState extends State <LinkDialog > {
14838 late String _link;
14939 late String _text;
15040
@@ -217,7 +107,7 @@ class _LinkDialogState extends State<_LinkDialog> {
217107 autofillHints: const [AutofillHints .url],
218108 autocorrect: false ,
219109 onEditingComplete: () {
220- if (! _canPress ()) {
110+ if (! canPress ()) {
221111 return ;
222112 }
223113 _applyLink ();
@@ -235,13 +125,13 @@ class _LinkDialogState extends State<_LinkDialog> {
235125 Widget _okButton () {
236126 if (widget.action != null ) {
237127 return widget.action! .builder (
238- _canPress (),
128+ canPress (),
239129 _applyLink,
240130 );
241131 }
242132
243133 return TextButton (
244- onPressed: _canPress () ? _applyLink : null ,
134+ onPressed: canPress () ? _applyLink : null ,
245135 child: Text (
246136 context.loc.ok,
247137 style: widget.dialogTheme? .buttonTextStyle,
@@ -256,7 +146,9 @@ class _LinkDialogState extends State<_LinkDialog> {
256146 legacyRegex: widget.legacyLinkRegExp,
257147 );
258148
259- bool _canPress () {
149+ @visibleForTesting
150+ @internal
151+ bool canPress () {
260152 if (_text.isEmpty || _link.isEmpty) {
261153 return false ;
262154 }
0 commit comments