Skip to content

Commit d100a2e

Browse files
committed
fix unchecked dispose issues
1 parent 37e1e5e commit d100a2e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/src/code_field/code_controller.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class CodeController extends TextEditingController {
125125
@visibleForTesting
126126
TextSpan? lastTextSpan;
127127

128+
bool _disposed = false;
129+
128130
late final actions = <Type, Action<Intent>>{
129131
CommentUncommentIntent: CommentUncommentAction(controller: this),
130132
CopySelectionTextIntent: CopyAction(controller: this),
@@ -233,6 +235,10 @@ class CodeController extends TextEditingController {
233235
return;
234236
}
235237

238+
if (_disposed) {
239+
return;
240+
}
241+
236242
analysisResult = result;
237243
_lastAnalyzedText = codeSentToAnalysis.text;
238244
notifyListeners();
@@ -971,6 +977,7 @@ class CodeController extends TextEditingController {
971977

972978
@override
973979
void dispose() {
980+
_disposed = true;
974981
_debounce?.cancel();
975982
historyController.dispose();
976983
searchController.dispose();

lib/src/code_field/code_field.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ class _CodeFieldState extends State<CodeField> {
261261
disableSpellCheckIfWeb();
262262

263263
WidgetsBinding.instance.addPostFrameCallback((_) {
264+
if(!mounted){
265+
return;
266+
}
264267
final double width = _codeFieldKey.currentContext!.size!.width;
265268
final double height = _codeFieldKey.currentContext!.size!.height;
266269
windowSize = Size(width, height);
@@ -312,6 +315,9 @@ class _CodeFieldState extends State<CodeField> {
312315
void rebuild() {
313316
setState(() {
314317
WidgetsBinding.instance.addPostFrameCallback((_) {
318+
if(!mounted){
319+
return;
320+
}
315321
// For some reason _codeFieldKey.currentContext is null in tests
316322
// so check first.
317323
final context = _codeFieldKey.currentContext;

0 commit comments

Comments
 (0)