|
@@ -300,7 +300,6 @@ class LinkButton extends StatefulWidget {
|
300
|
300
|
}
|
301
|
301
|
|
302
|
302
|
class _LinkButtonState extends State<LinkButton> {
|
303
|
|
- final FocusNode _focusNode = FocusNode();
|
304
|
303
|
final TextEditingController _inputController = TextEditingController();
|
305
|
304
|
Key _inputKey;
|
306
|
305
|
bool _formatError = false;
|
|
@@ -308,23 +307,6 @@ class _LinkButtonState extends State<LinkButton> {
|
308
|
307
|
|
309
|
308
|
bool get isEditing => _inputKey != null;
|
310
|
309
|
|
311
|
|
- @override
|
312
|
|
- void dispose() {
|
313
|
|
- _focusNode.dispose();
|
314
|
|
- super.dispose();
|
315
|
|
- }
|
316
|
|
-
|
317
|
|
- @override
|
318
|
|
- void didChangeDependencies() {
|
319
|
|
- super.didChangeDependencies();
|
320
|
|
- final toolbar = ZefyrToolbar.of(context);
|
321
|
|
- if (_editor != toolbar.editor) {
|
322
|
|
- _editor?.setToolbarFocusNode(null);
|
323
|
|
- _editor = toolbar.editor;
|
324
|
|
- _editor.setToolbarFocusNode(_focusNode);
|
325
|
|
- }
|
326
|
|
- }
|
327
|
|
-
|
328
|
310
|
@override
|
329
|
311
|
Widget build(BuildContext context) {
|
330
|
312
|
final toolbar = ZefyrToolbar.of(context);
|
|
@@ -457,7 +439,6 @@ class _LinkButtonState extends State<LinkButton> {
|
457
|
439
|
: _LinkInput(
|
458
|
440
|
key: _inputKey,
|
459
|
441
|
controller: _inputController,
|
460
|
|
- focusNode: _focusNode,
|
461
|
442
|
formatError: _formatError,
|
462
|
443
|
);
|
463
|
444
|
final items = <Widget>[Expanded(child: body)];
|
|
@@ -494,16 +475,13 @@ class _LinkButtonState extends State<LinkButton> {
|
494
|
475
|
}
|
495
|
476
|
|
496
|
477
|
class _LinkInput extends StatefulWidget {
|
497
|
|
- final FocusNode focusNode;
|
498
|
478
|
final TextEditingController controller;
|
499
|
479
|
final bool formatError;
|
500
|
480
|
|
501
|
|
- const _LinkInput({
|
502
|
|
- Key key,
|
503
|
|
- @required this.focusNode,
|
504
|
|
- @required this.controller,
|
505
|
|
- this.formatError: false,
|
506
|
|
- }) : super(key: key);
|
|
481
|
+ const _LinkInput(
|
|
482
|
+ {Key key, @required this.controller, this.formatError: false})
|
|
483
|
+ : super(key: key);
|
|
484
|
+
|
507
|
485
|
@override
|
508
|
486
|
_LinkInputState createState() {
|
509
|
487
|
return new _LinkInputState();
|
|
@@ -511,20 +489,37 @@ class _LinkInput extends StatefulWidget {
|
511
|
489
|
}
|
512
|
490
|
|
513
|
491
|
class _LinkInputState extends State<_LinkInput> {
|
|
492
|
+ final FocusNode _focusNode = FocusNode();
|
|
493
|
+
|
514
|
494
|
bool _didAutoFocus = false;
|
|
495
|
+ ZefyrEditorScope _editor;
|
515
|
496
|
|
516
|
497
|
@override
|
517
|
498
|
void didChangeDependencies() {
|
518
|
499
|
super.didChangeDependencies();
|
|
500
|
+ final toolbar = ZefyrToolbar.of(context);
|
519
|
501
|
if (!_didAutoFocus) {
|
520
|
|
- FocusScope.of(context).requestFocus(widget.focusNode);
|
|
502
|
+ FocusScope.of(context).requestFocus(_focusNode);
|
521
|
503
|
_didAutoFocus = true;
|
522
|
504
|
}
|
|
505
|
+
|
|
506
|
+ if (_editor != toolbar.editor) {
|
|
507
|
+ _editor?.setToolbarFocusNode(null);
|
|
508
|
+ _editor = toolbar.editor;
|
|
509
|
+ _editor.setToolbarFocusNode(_focusNode);
|
|
510
|
+ }
|
|
511
|
+ }
|
|
512
|
+
|
|
513
|
+ @override
|
|
514
|
+ void dispose() {
|
|
515
|
+ _focusNode.dispose();
|
|
516
|
+ _editor = null;
|
|
517
|
+ super.dispose();
|
523
|
518
|
}
|
524
|
519
|
|
525
|
520
|
@override
|
526
|
521
|
Widget build(BuildContext context) {
|
527
|
|
- FocusScope.of(context).reparentIfNeeded(widget.focusNode);
|
|
522
|
+ FocusScope.of(context).reparentIfNeeded(_focusNode);
|
528
|
523
|
|
529
|
524
|
final theme = Theme.of(context);
|
530
|
525
|
final toolbarTheme = ZefyrTheme.of(context).toolbarTheme;
|
|
@@ -534,7 +529,7 @@ class _LinkInputState extends State<_LinkInput> {
|
534
|
529
|
return TextField(
|
535
|
530
|
style: style,
|
536
|
531
|
keyboardType: TextInputType.url,
|
537
|
|
- focusNode: widget.focusNode,
|
|
532
|
+ focusNode: _focusNode,
|
538
|
533
|
controller: widget.controller,
|
539
|
534
|
// autofocus: true,
|
540
|
535
|
decoration: new InputDecoration(
|