Skip to content

Fix controller/focusNode disposal causing rendering issues on parent setState#8

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-rendering-issue-chips-input
Open

Fix controller/focusNode disposal causing rendering issues on parent setState#8
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-rendering-issue-chips-input

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 26, 2025

The widget unconditionally disposed externally-provided controllers and focus nodes, violating Flutter ownership semantics. When parent widgets called setState() via onChange callbacks, disposed controllers would cause errors or incorrect state.

Changes

Core Fix

  • Track resource ownership via _isControllerInternal and _isFocusNodeInternal flags
  • Dispose only internally-created resources in dispose()

Tests

  • External controller survives widget disposal and parent rebuilds
  • Internal controller properly disposed
  • External controller with onChange triggering setState works correctly

Example

  • Added example_on_changed.dart demonstrating external controller with onChange callback

Before/After

// Before - always disposed, even if external
@override
void dispose() {
  _chipsAutocompleteController.dispose();
  _focusNode.dispose();
  super.dispose();
}

// After - conditional disposal based on ownership
@override
void dispose() {
  if (_isControllerInternal) {
    _chipsAutocompleteController.dispose();
  }
  if (_isFocusNodeInternal) {
    _focusNode.dispose();
  }
  super.dispose();
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • canonical-bos01.cdn.snapcraftcontent.com
    • Triggering command: /usr/lib/snapd/snapd (dns block)
  • https://storage.googleapis.com/flutter_infra_release/flutter/035316565ad77281a75305515e4682e6c4c6f7ca/dart-sdk-linux-x64.zip
    • Triggering command: curl --retry 3 --continue-at - --location --output /tmp/flutter/bin/cache/dart-sdk-linux-x64.zip REDACTED (http block)
  • https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.24.5-stable.tar.xz
    • Triggering command: wget -q REDACTED -O flutter.tar.xz (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Rendering goes weird if onChange called and if controller property is set</issue_title>
<issue_description>I've noticed a rendering problem with ChipsInputAutocomplete when...

  1. The controller property is set; and
  2. The onChange handler is set that causes a 'setState()' call

</issue_description>

Comments on the Issue (you are @copilot in this section)

@EmilyMoonstone Can you provide a code example?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits October 26, 2025 12:10
Co-authored-by: EmilyMoonstone <81753412+EmilyMoonstone@users.noreply.github.com>
Co-authored-by: EmilyMoonstone <81753412+EmilyMoonstone@users.noreply.github.com>
Co-authored-by: EmilyMoonstone <81753412+EmilyMoonstone@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix rendering issue with ChipsInputAutocomplete onChange Fix controller/focusNode disposal causing rendering issues on parent setState Oct 26, 2025
Copilot AI requested a review from EmilyMoonstone October 26, 2025 12:15
@EmilyMoonstone EmilyMoonstone marked this pull request as ready for review October 26, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering goes weird if onChange called and if controller property is set

2 participants