Skip to content

Commit bc93fac

Browse files
angelosilvestrematthew-carroll
authored andcommitted
[SuperEditor] - Detach plugins in dispose() (Resolves #2790) (#2793)
1 parent d1c0af9 commit bc93fac

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

super_editor/lib/src/default_editor/super_editor.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)