fix: remove leaked NoteModel listener in NoteEditController#40
Merged
shukebeta merged 2 commits intoJun 16, 2026
Merged
Conversation
The anonymous listener registered in initialize() via addPostFrameCallback could not be removed, so any notifyListeners() call after the widget was disposed (e.g. in-flight image upload completing post-navigation) would write to an already-disposed TextEditingController. Hoists the lambda to a named _syncControllerFromModel method, stores the NoteModel reference, and removes the listener in dispose(). Guards the addPostFrameCallback body with _disposed so that dispose-before-frame races also produce a no-op. Adds two regression tests covering the post-dispose and race paths. Closes #37 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add assert in initialize() to catch double-initialization in debug builds - Null _noteModel in dispose() after removeListener to release the reference - Fix weak test: setUploading(false) is a no-op when already false; call setUploading(true) first so notifyListeners() actually fires in the dispose-before-frame-callback test Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NoteEditController.initialize()to a named_syncControllerFromModelmethod so it can be removed indispose()NoteModelreference and callsremoveListenerbeforetextController.dispose()addPostFrameCallbackbody with_disposedto handle the race wheredispose()runs before the frame callback firesTest plan
flutter test test/controllers/note_edit_controller_test.dart— 12 tests pass (2 new regression tests added)flutter analyze— no issuessetUploading(true/false)andsetPasting(true/false)do not throwCloses #37
🤖 Generated with Claude Code