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 ;
102
4
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' ;
105
7
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' ;
125
14
126
- class _LinkDialog extends StatefulWidget {
127
- const _LinkDialog ({
15
+ class LinkDialog extends StatefulWidget {
16
+ const LinkDialog ({
128
17
required this .validateLink,
18
+ super .key,
129
19
this .dialogTheme,
130
20
this .link,
131
21
this .text,
@@ -141,10 +31,10 @@ class _LinkDialog extends StatefulWidget {
141
31
final LinkDialogAction ? action;
142
32
143
33
@override
144
- _LinkDialogState createState () => _LinkDialogState ();
34
+ LinkDialogState createState () => LinkDialogState ();
145
35
}
146
36
147
- class _LinkDialogState extends State <_LinkDialog > {
37
+ class LinkDialogState extends State <LinkDialog > {
148
38
late String _link;
149
39
late String _text;
150
40
@@ -217,7 +107,7 @@ class _LinkDialogState extends State<_LinkDialog> {
217
107
autofillHints: const [AutofillHints .url],
218
108
autocorrect: false ,
219
109
onEditingComplete: () {
220
- if (! _canPress ()) {
110
+ if (! canPress ()) {
221
111
return ;
222
112
}
223
113
_applyLink ();
@@ -235,13 +125,13 @@ class _LinkDialogState extends State<_LinkDialog> {
235
125
Widget _okButton () {
236
126
if (widget.action != null ) {
237
127
return widget.action! .builder (
238
- _canPress (),
128
+ canPress (),
239
129
_applyLink,
240
130
);
241
131
}
242
132
243
133
return TextButton (
244
- onPressed: _canPress () ? _applyLink : null ,
134
+ onPressed: canPress () ? _applyLink : null ,
245
135
child: Text (
246
136
context.loc.ok,
247
137
style: widget.dialogTheme? .buttonTextStyle,
@@ -256,7 +146,9 @@ class _LinkDialogState extends State<_LinkDialog> {
256
146
legacyRegex: widget.legacyLinkRegExp,
257
147
);
258
148
259
- bool _canPress () {
149
+ @visibleForTesting
150
+ @internal
151
+ bool canPress () {
260
152
if (_text.isEmpty || _link.isEmpty) {
261
153
return false ;
262
154
}
0 commit comments