Skip to content

Dispose TextEditingController in IndexedStack example#186375

Open
BilalRehman08 wants to merge 1 commit into
flutter:masterfrom
BilalRehman08:fix/indexed-stack-dispose-controller
Open

Dispose TextEditingController in IndexedStack example#186375
BilalRehman08 wants to merge 1 commit into
flutter:masterfrom
BilalRehman08:fix/indexed-stack-dispose-controller

Conversation

@BilalRehman08
Copy link
Copy Markdown

Description

The _IndexedStackExampleState class in the IndexedStack API example creates a TextEditingController but never disposes it, causing a resource leak.

Added a dispose() override that calls fieldText.dispose() before super.dispose().

@override
void dispose() {
  fieldText.dispose();
  super.dispose();
}

Fixes #186324

Tests

Existing tests in examples/api/test/widgets/basic/indexed_stack.0_test.dart cover the example. No new tests needed for a dispose fix.

@flutter-dashboard
Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels May 11, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a dispose method to the _IndexedStackExampleState class in examples/api/lib/widgets/basic/indexed_stack.0.dart. This implementation ensures that the TextEditingController is properly disposed of when the widget is removed from the tree, preventing potential memory leaks. I have no feedback to provide.

The _IndexedStackExampleState class created a TextEditingController
but never disposed it, causing a resource leak. Added dispose() to
properly clean up the controller when the widget is removed from the tree.

Fixes flutter#186324
@BilalRehman08 BilalRehman08 force-pushed the fix/indexed-stack-dispose-controller branch from 90202a9 to 34e70f7 Compare May 11, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexedStack example does not dispose of the TextField controller

1 participant