|
@@ -59,15 +59,15 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
59
|
59
|
// New public members
|
60
|
60
|
//
|
61
|
61
|
|
62
|
|
- /// Focus node of this widget.
|
63
|
|
- FocusNode get focusNode => widget.focusNode;
|
64
|
|
-
|
65
|
62
|
/// Document controlled by this widget.
|
66
|
63
|
NotusDocument get document => widget.controller.document;
|
67
|
64
|
|
68
|
65
|
/// Current text selection.
|
69
|
66
|
TextSelection get selection => widget.controller.selection;
|
70
|
67
|
|
|
68
|
+ FocusNode _focusNode;
|
|
69
|
+ FocusAttachment _focusAttachment;
|
|
70
|
+
|
71
|
71
|
/// Express interest in interacting with the keyboard.
|
72
|
72
|
///
|
73
|
73
|
/// If this control is already attached to the keyboard, this function will
|
|
@@ -76,20 +76,20 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
76
|
76
|
/// focus, the control will then attach to the keyboard and request that the
|
77
|
77
|
/// keyboard become visible.
|
78
|
78
|
void requestKeyboard() {
|
79
|
|
- if (focusNode.hasFocus)
|
|
79
|
+ if (_focusNode.hasFocus)
|
80
|
80
|
_input.openConnection(widget.controller.plainTextEditingValue);
|
81
|
81
|
else
|
82
|
|
- FocusScope.of(context).requestFocus(focusNode);
|
|
82
|
+ FocusScope.of(context).requestFocus(_focusNode);
|
83
|
83
|
}
|
84
|
84
|
|
85
|
85
|
void focusOrUnfocusIfNeeded() {
|
86
|
86
|
if (!_didAutoFocus && widget.autofocus && widget.enabled) {
|
87
|
|
- FocusScope.of(context).autofocus(focusNode);
|
|
87
|
+ FocusScope.of(context).autofocus(_focusNode);
|
88
|
88
|
_didAutoFocus = true;
|
89
|
89
|
}
|
90
|
|
- if (!widget.enabled && focusNode.hasFocus) {
|
|
90
|
+ if (!widget.enabled && _focusNode.hasFocus) {
|
91
|
91
|
_didAutoFocus = false;
|
92
|
|
- focusNode.unfocus();
|
|
92
|
+ _focusNode.unfocus();
|
93
|
93
|
}
|
94
|
94
|
}
|
95
|
95
|
|
|
@@ -99,7 +99,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
99
|
99
|
|
100
|
100
|
@override
|
101
|
101
|
Widget build(BuildContext context) {
|
102
|
|
- FocusScope.of(context).reparentIfNeeded(focusNode);
|
|
102
|
+ _focusAttachment.reparent();
|
103
|
103
|
super.build(context); // See AutomaticKeepAliveState.
|
104
|
104
|
|
105
|
105
|
Widget body = ListBody(children: _buildChildren(context));
|
|
@@ -127,7 +127,9 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
127
|
127
|
|
128
|
128
|
@override
|
129
|
129
|
void initState() {
|
|
130
|
+ _focusNode = widget.focusNode;
|
130
|
131
|
super.initState();
|
|
132
|
+ _focusAttachment = _focusNode.attach(context);
|
131
|
133
|
_input = new InputConnectionController(_handleRemoteValueChange);
|
132
|
134
|
_updateSubscriptions();
|
133
|
135
|
}
|
|
@@ -135,6 +137,11 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
135
|
137
|
@override
|
136
|
138
|
void didUpdateWidget(ZefyrEditableText oldWidget) {
|
137
|
139
|
super.didUpdateWidget(oldWidget);
|
|
140
|
+ if (_focusNode != widget.focusNode) {
|
|
141
|
+ _focusAttachment.detach();
|
|
142
|
+ _focusNode = widget.focusNode;
|
|
143
|
+ _focusAttachment = _focusNode.attach(context);
|
|
144
|
+ }
|
138
|
145
|
_updateSubscriptions(oldWidget);
|
139
|
146
|
focusOrUnfocusIfNeeded();
|
140
|
147
|
}
|
|
@@ -151,13 +158,14 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
151
|
158
|
if (_cursorTimer != scope.cursorTimer) {
|
152
|
159
|
_cursorTimer?.stop();
|
153
|
160
|
_cursorTimer = scope.cursorTimer;
|
154
|
|
- _cursorTimer.startOrStop(focusNode, selection);
|
|
161
|
+ _cursorTimer.startOrStop(_focusNode, selection);
|
155
|
162
|
}
|
156
|
163
|
focusOrUnfocusIfNeeded();
|
157
|
164
|
}
|
158
|
165
|
|
159
|
166
|
@override
|
160
|
167
|
void dispose() {
|
|
168
|
+ _focusAttachment.detach();
|
161
|
169
|
_cancelSubscriptions();
|
162
|
170
|
super.dispose();
|
163
|
171
|
}
|
|
@@ -167,7 +175,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
167
|
175
|
//
|
168
|
176
|
|
169
|
177
|
@override
|
170
|
|
- bool get wantKeepAlive => focusNode.hasFocus;
|
|
178
|
+ bool get wantKeepAlive => _focusNode.hasFocus;
|
171
|
179
|
|
172
|
180
|
//
|
173
|
181
|
// Private members
|
|
@@ -215,7 +223,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
215
|
223
|
void _updateSubscriptions([ZefyrEditableText oldWidget]) {
|
216
|
224
|
if (oldWidget == null) {
|
217
|
225
|
widget.controller.addListener(_handleLocalValueChange);
|
218
|
|
- focusNode.addListener(_handleFocusChange);
|
|
226
|
+ _focusNode.addListener(_handleFocusChange);
|
219
|
227
|
return;
|
220
|
228
|
}
|
221
|
229
|
|
|
@@ -234,7 +242,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
234
|
242
|
void _cancelSubscriptions() {
|
235
|
243
|
_renderContext.removeListener(_handleRenderContextChange);
|
236
|
244
|
widget.controller.removeListener(_handleLocalValueChange);
|
237
|
|
- focusNode.removeListener(_handleFocusChange);
|
|
245
|
+ _focusNode.removeListener(_handleFocusChange);
|
238
|
246
|
_input.closeConnection();
|
239
|
247
|
_cursorTimer.stop();
|
240
|
248
|
}
|
|
@@ -247,7 +255,7 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
247
|
255
|
requestKeyboard();
|
248
|
256
|
}
|
249
|
257
|
_input.updateRemoteValue(widget.controller.plainTextEditingValue);
|
250
|
|
- _cursorTimer.startOrStop(focusNode, selection);
|
|
258
|
+ _cursorTimer.startOrStop(_focusNode, selection);
|
251
|
259
|
setState(() {
|
252
|
260
|
// nothing to update internally.
|
253
|
261
|
});
|
|
@@ -255,8 +263,8 @@ class _ZefyrEditableTextState extends State<ZefyrEditableText>
|
255
|
263
|
|
256
|
264
|
void _handleFocusChange() {
|
257
|
265
|
_input.openOrCloseConnection(
|
258
|
|
- focusNode, widget.controller.plainTextEditingValue);
|
259
|
|
- _cursorTimer.startOrStop(focusNode, selection);
|
|
266
|
+ _focusNode, widget.controller.plainTextEditingValue);
|
|
267
|
+ _cursorTimer.startOrStop(_focusNode, selection);
|
260
|
268
|
updateKeepAlive();
|
261
|
269
|
}
|
262
|
270
|
|