File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -534,6 +534,10 @@ class SuperEditorState extends State<SuperEditor> {
534534 }
535535 }
536536
537+ for (final plugin in widget.plugins) {
538+ plugin.detach (widget.editor);
539+ }
540+
537541 _iosControlsController.dispose ();
538542 _androidControlsController.dispose ();
539543
Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:flutter_test/flutter_test.dart' ;
3+ import 'package:flutter_test_runners/flutter_test_runners.dart' ;
4+ import 'package:super_editor/super_editor.dart' ;
5+
6+ import 'supereditor_test_tools.dart' ;
7+
8+ void main () {
9+ group ('SuperEditor > plugins >' , () {
10+ testWidgetsOnAllPlatforms ('are detached when the editor is disposed' , (tester) async {
11+ final plugin = _FakePlugin ();
12+
13+ await tester //
14+ .createDocument ()
15+ .withSingleParagraph ()
16+ .withPlugin (plugin)
17+ .pump ();
18+
19+ // Ensure the plugin was not attached initially.
20+ expect (plugin.wasDetached, isFalse);
21+
22+ // Pump another widget tree to dispose SuperEditor.
23+ await tester.pumpWidget (Container ());
24+
25+ // Ensure the plugin was detached.
26+ expect (plugin.wasDetached, isTrue);
27+ });
28+ });
29+ }
30+
31+ /// A plugin that tracks whether it was detached.
32+ class _FakePlugin extends SuperEditorPlugin {
33+ bool get wasDetached => _wasDetached;
34+ bool _wasDetached = false ;
35+
36+ @override
37+ void detach (Editor editor) {
38+ _wasDetached = true ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments