Quellcode durchsuchen

Updated to resolve breaking changes in Flutter dev channel

Anatoly Pulyaevskiy vor 5 Jahren
Ursprung
Commit
56def8e0f4

+ 1
- 1
packages/zefyr/example/ios/Podfile.lock Datei anzeigen

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

+ 24
- 16
packages/zefyr/lib/src/widgets/editable_text.dart Datei anzeigen

@@ -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
 

+ 2
- 2
packages/zefyr/lib/src/widgets/input.dart Datei anzeigen

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

+ 19
- 3
packages/zefyr/lib/src/widgets/selection.dart Datei anzeigen

@@ -468,19 +468,35 @@ class _SelectionToolbarState extends State<_SelectionToolbar> {
468 468
     }
469 469
     final boxes = block.getEndpointsForSelection(selection);
470 470
     // Find the horizontal midpoint, just above the selected text.
471
-    final Offset midpoint = new Offset(
471
+    Offset midpoint = new Offset(
472 472
       (boxes.length == 1)
473 473
           ? (boxes[0].start + boxes[0].end) / 2.0
474 474
           : (boxes[0].start + boxes[1].start) / 2.0,
475 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 494
     final Rect editingRegion = new Rect.fromPoints(
479 495
       block.localToGlobal(Offset.zero),
480 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 500
     return new CompositedTransformFollower(
485 501
       link: block.layerLink,
486 502
       showWhenUnlinked: false,

+ 1
- 1
packages/zefyr/pubspec.yaml Datei anzeigen

@@ -5,7 +5,7 @@ author: Anatoly Pulyaevskiy <anatoly.pulyaevskiy@gmail.com>
5 5
 homepage: https://github.com/memspace/zefyr
6 6
 
7 7
 environment:
8
-  sdk: '>=2.0.0-dev.58.0 <3.0.0'
8
+  sdk: '>=2.1.0 <3.0.0'
9 9
 
10 10
 dependencies:
11 11
   flutter: