Browse Source

Updated to resolve breaking changes in Flutter dev channel

Anatoly Pulyaevskiy 5 years ago
parent
commit
56def8e0f4

+ 1
- 1
packages/zefyr/example/ios/Podfile.lock View File

20
 
20
 
21
 SPEC CHECKSUMS:
21
 SPEC CHECKSUMS:
22
   Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
22
   Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
23
-  image_picker: ee00aab0487cedc80a304085219503cc6d0f2e22
23
+  image_picker: 86b84c4fe89267356a1f17297a45b5d317ebd2e7
24
   url_launcher: 92b89c1029a0373879933c21642958c874539095
24
   url_launcher: 92b89c1029a0373879933c21642958c874539095
25
 
25
 
26
 PODFILE CHECKSUM: 1e5af4103afd21ca5ead147d7b81d06f494f51a2
26
 PODFILE CHECKSUM: 1e5af4103afd21ca5ead147d7b81d06f494f51a2

+ 24
- 16
packages/zefyr/lib/src/widgets/editable_text.dart View File

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

+ 2
- 2
packages/zefyr/lib/src/widgets/input.dart View File

146
       final diff = fastDiff(oldText, text, cursorPosition);
146
       final diff = fastDiff(oldText, text, cursorPosition);
147
       onValueChanged(diff.start, diff.deleted, diff.inserted, value.selection);
147
       onValueChanged(diff.start, diff.deleted, diff.inserted, value.selection);
148
     } catch (e, trace) {
148
     } catch (e, trace) {
149
-      FlutterError.reportError(new FlutterErrorDetails(
149
+      FlutterError.reportError(FlutterErrorDetails(
150
         exception: e,
150
         exception: e,
151
         stack: trace,
151
         stack: trace,
152
         library: 'Zefyr',
152
         library: 'Zefyr',
153
-        context: 'while updating editing value',
153
+        context: ErrorSummary('while updating editing value'),
154
       ));
154
       ));
155
       rethrow;
155
       rethrow;
156
     }
156
     }

+ 19
- 3
packages/zefyr/lib/src/widgets/selection.dart View File

468
     }
468
     }
469
     final boxes = block.getEndpointsForSelection(selection);
469
     final boxes = block.getEndpointsForSelection(selection);
470
     // Find the horizontal midpoint, just above the selected text.
470
     // Find the horizontal midpoint, just above the selected text.
471
-    final Offset midpoint = new Offset(
471
+    Offset midpoint = new Offset(
472
       (boxes.length == 1)
472
       (boxes.length == 1)
473
           ? (boxes[0].start + boxes[0].end) / 2.0
473
           ? (boxes[0].start + boxes[0].end) / 2.0
474
           : (boxes[0].start + boxes[1].start) / 2.0,
474
           : (boxes[0].start + boxes[1].start) / 2.0,
475
       boxes[0].bottom - block.preferredLineHeight,
475
       boxes[0].bottom - block.preferredLineHeight,
476
     );
476
     );
477
+    List<TextSelectionPoint> endpoints;
478
+    if (boxes.length == 1) {
479
+      midpoint = Offset((boxes[0].start + boxes[0].end) / 2.0,
480
+          boxes[0].bottom - block.preferredLineHeight);
481
+      final Offset start = Offset(boxes[0].start, block.preferredLineHeight);
482
+      endpoints = <TextSelectionPoint>[TextSelectionPoint(start, null)];
483
+    } else {
484
+      midpoint = Offset((boxes[0].start + boxes[1].start) / 2.0,
485
+          boxes[0].bottom - block.preferredLineHeight);
486
+      final Offset start = Offset(boxes.first.start, boxes.first.bottom);
487
+      final Offset end = Offset(boxes.last.end, boxes.last.bottom);
488
+      endpoints = <TextSelectionPoint>[
489
+        TextSelectionPoint(start, boxes.first.direction),
490
+        TextSelectionPoint(end, boxes.last.direction),
491
+      ];
492
+    }
477
 
493
 
478
     final Rect editingRegion = new Rect.fromPoints(
494
     final Rect editingRegion = new Rect.fromPoints(
479
       block.localToGlobal(Offset.zero),
495
       block.localToGlobal(Offset.zero),
480
       block.localToGlobal(block.size.bottomRight(Offset.zero)),
496
       block.localToGlobal(block.size.bottomRight(Offset.zero)),
481
     );
497
     );
482
-    final toolbar = widget.controls
483
-        .buildToolbar(context, editingRegion, midpoint, widget.delegate);
498
+    final toolbar = widget.controls.buildToolbar(
499
+        context, editingRegion, midpoint, endpoints, widget.delegate);
484
     return new CompositedTransformFollower(
500
     return new CompositedTransformFollower(
485
       link: block.layerLink,
501
       link: block.layerLink,
486
       showWhenUnlinked: false,
502
       showWhenUnlinked: false,

+ 1
- 1
packages/zefyr/pubspec.yaml View File

5
 homepage: https://github.com/memspace/zefyr
5
 homepage: https://github.com/memspace/zefyr
6
 
6
 
7
 environment:
7
 environment:
8
-  sdk: '>=2.0.0-dev.58.0 <3.0.0'
8
+  sdk: '>=2.1.0 <3.0.0'
9
 
9
 
10
 dependencies:
10
 dependencies:
11
   flutter:
11
   flutter: