Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions super_editor/lib/src/default_editor/super_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ class SuperEditorState extends State<SuperEditor> {
}
}

for (final plugin in widget.plugins) {
plugin.detach(widget.editor);
}

_iosControlsController.dispose();
_androidControlsController.dispose();

Expand Down
40 changes: 40 additions & 0 deletions super_editor/test/super_editor/supereditor_plugin_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_test_runners/flutter_test_runners.dart';
import 'package:super_editor/super_editor.dart';

import 'supereditor_test_tools.dart';

void main() {
group('SuperEditor > plugins >', () {
testWidgetsOnAllPlatforms('are detached when the editor is disposed', (tester) async {
final plugin = _FakePlugin();

await tester //
.createDocument()
.withSingleParagraph()
.withPlugin(plugin)
.pump();

// Ensure the plugin was not attached initially.
expect(plugin.wasDetached, isFalse);

// Pump another widget tree to dispose SuperEditor.
await tester.pumpWidget(Container());

// Ensure the plugin was detached.
expect(plugin.wasDetached, isTrue);
});
});
}

/// A plugin that tracks whether it was detached.
class _FakePlugin extends SuperEditorPlugin {
bool get wasDetached => _wasDetached;
bool _wasDetached = false;

@override
void detach(Editor editor) {
_wasDetached = true;
}
}
Loading