Quellcode durchsuchen

Fixed error on Android when disabling editor in example app

Anatoly Pulyaevskiy vor 6 Jahren
Ursprung
Commit
d29e6d4987

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

@@ -173,6 +173,9 @@ class _ZefyrSelectionOverlayState extends State<ZefyrSelectionOverlay>
173 173
   bool _didCaretTap = false;
174 174
 
175 175
   void _updateToolbar() {
176
+    if (!mounted) {
177
+      return;
178
+    }
176 179
     final editor = ZefyrEditor.of(context);
177 180
     final selection = editor.selection;
178 181
     final focusOwner = editor.focusOwner;

+ 36
- 1
packages/zefyr/test/testing.dart Datei anzeigen

@@ -26,7 +26,7 @@ class EditorSandBox {
26 26
     document ??= NotusDocument.fromDelta(delta);
27 27
     var controller = ZefyrController(document);
28 28
 
29
-    Widget widget = ZefyrEditor(controller: controller, focusNode: focusNode);
29
+    Widget widget = _ZefyrSandbox(controller: controller, focusNode: focusNode);
30 30
     if (theme != null) {
31 31
       widget = ZefyrTheme(data: theme, child: widget);
32 32
     }
@@ -52,6 +52,12 @@ class EditorSandBox {
52 52
     return tester.pumpAndSettle();
53 53
   }
54 54
 
55
+  Future<void> disable() {
56
+    _ZefyrSandboxState state = tester.state(find.byType(_ZefyrSandbox));
57
+    state.disable();
58
+    return tester.pumpAndSettle();
59
+  }
60
+
55 61
   Future<void> tapEditor() async {
56 62
     await tester.pumpWidget(widget);
57 63
     await tester.tap(find.byType(ZefyrParagraph).first);
@@ -91,3 +97,32 @@ class EditorSandBox {
91 97
         matching: find.byType(Positioned));
92 98
   }
93 99
 }
100
+
101
+class _ZefyrSandbox extends StatefulWidget {
102
+  const _ZefyrSandbox({Key key, this.controller, this.focusNode})
103
+      : super(key: key);
104
+  final ZefyrController controller;
105
+  final FocusNode focusNode;
106
+
107
+  @override
108
+  _ZefyrSandboxState createState() => _ZefyrSandboxState();
109
+}
110
+
111
+class _ZefyrSandboxState extends State<_ZefyrSandbox> {
112
+  bool _enabled = true;
113
+
114
+  @override
115
+  Widget build(BuildContext context) {
116
+    return new ZefyrEditor(
117
+      controller: widget.controller,
118
+      focusNode: widget.focusNode,
119
+      enabled: _enabled,
120
+    );
121
+  }
122
+
123
+  void disable() {
124
+    setState(() {
125
+      _enabled = false;
126
+    });
127
+  }
128
+}

+ 9
- 0
packages/zefyr/test/widgets/editor_test.dart Datei anzeigen

@@ -36,5 +36,14 @@ void main() {
36 36
       expect(editor.findSelectionHandle(), findsNothing);
37 37
       expect(editor.selection, TextSelection.collapsed(offset: 3));
38 38
     });
39
+
40
+    testWidgets('toggle enabled state', (tester) async {
41
+      final editor = new EditorSandBox(tester: tester);
42
+      await editor.tapEditor();
43
+      await editor.updateSelection(base: 0, extent: 3);
44
+      await editor.disable();
45
+      ZefyrEditor widget = tester.widget(find.byType(ZefyrEditor));
46
+      expect(widget.enabled, isFalse);
47
+    });
39 48
   });
40 49
 }