Browse Source

Fixed error on Android when disabling editor in example app

Anatoly Pulyaevskiy 6 years ago
parent
commit
d29e6d4987

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

173
   bool _didCaretTap = false;
173
   bool _didCaretTap = false;
174
 
174
 
175
   void _updateToolbar() {
175
   void _updateToolbar() {
176
+    if (!mounted) {
177
+      return;
178
+    }
176
     final editor = ZefyrEditor.of(context);
179
     final editor = ZefyrEditor.of(context);
177
     final selection = editor.selection;
180
     final selection = editor.selection;
178
     final focusOwner = editor.focusOwner;
181
     final focusOwner = editor.focusOwner;

+ 36
- 1
packages/zefyr/test/testing.dart View File

26
     document ??= NotusDocument.fromDelta(delta);
26
     document ??= NotusDocument.fromDelta(delta);
27
     var controller = ZefyrController(document);
27
     var controller = ZefyrController(document);
28
 
28
 
29
-    Widget widget = ZefyrEditor(controller: controller, focusNode: focusNode);
29
+    Widget widget = _ZefyrSandbox(controller: controller, focusNode: focusNode);
30
     if (theme != null) {
30
     if (theme != null) {
31
       widget = ZefyrTheme(data: theme, child: widget);
31
       widget = ZefyrTheme(data: theme, child: widget);
32
     }
32
     }
52
     return tester.pumpAndSettle();
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
   Future<void> tapEditor() async {
61
   Future<void> tapEditor() async {
56
     await tester.pumpWidget(widget);
62
     await tester.pumpWidget(widget);
57
     await tester.tap(find.byType(ZefyrParagraph).first);
63
     await tester.tap(find.byType(ZefyrParagraph).first);
91
         matching: find.byType(Positioned));
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 View File

36
       expect(editor.findSelectionHandle(), findsNothing);
36
       expect(editor.findSelectionHandle(), findsNothing);
37
       expect(editor.selection, TextSelection.collapsed(offset: 3));
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
 }