Skip to content

Fix external controller disposal causing scroll errors#9

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-autocomplete-scroll-error
Draft

Fix external controller disposal causing scroll errors#9
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-autocomplete-scroll-error

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 26, 2025

ChipsInputAutocomplete was disposing externally-provided controllers and focus nodes when scrolled out of view in ListView, causing crashes when parent widgets accessed them later.

Changes

Core Fix (lib/src/chips_input_autocomplete.dart)

  • Track ownership of controller and FocusNode with _controllerCreatedInternally and _focusNodeCreatedInternally flags
  • Conditionally dispose only internally-created resources in dispose()

Tests (test/chips_input_autocomplete_test.dart)

  • Verify external controllers remain usable after widget disposal
  • Verify external FocusNodes remain usable after widget disposal
  • Verify scrolling behavior in ListView with external controller

Example (example/lib/example_scroll_form.dart)

  • Demonstrate usage with external controller in scrollable form

Example

// Before: This would crash when scrolled
final controller = ChipsAutocompleteController();
ListView(
  children: [
    ChipsInputAutocomplete(controller: controller), // ❌ Crashes on scroll
  ],
)

// After: Controller ownership is respected
ListView(
  children: [
    ChipsInputAutocomplete(controller: controller), // ✅ Works correctly
  ],
)

Follows standard Flutter ownership pattern (matches TextField/TextEditingController behavior).

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:

  • fvm.app
    • Triggering command: curl -fsSL REDACTED (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)
    • Triggering command: curl --retry 3 --location --output /tmp/flutter/bin/cache/dart-sdk-linux-x64.zip REDACTED (http block)
    • Triggering command: curl -L REDACTED (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>Error on Scroll if controller property is set</issue_title>
<issue_description>

AutoComplete widget create an error onscroll if the controller property is set.

In order to recreate set Autocomplete is a large form that needs to be scrolled.
It seems like it's disposed or needs rebuilt when it's no longer on screen.

`
Form(
key: formkey,
child: ListView(
shrinkWrap: true,
children: [

                TextField(
                  controller: controllers['CompanyName'],
                  decoration: InputDecoration(
                    hintText: "Name of Company",
                    enabledBorder: AppStyles.authBorder,
                    focusedBorder: AppStyles.authBorder,
                    border: AppStyles.authBorder,
                    fillColor: Colors.transparent,
                    filled: true,
                  ),
                ),
        
                ChipsInputAutocomplete(
                  options: industryValues,
                  createCharacter: ' ',
                  controller: chipController,
                  widgetContainerDecoration: BoxDecoration(
                    border: Border.all(color: Colors.grey),
                    borderRadius: BorderRadius.circular(10),
                  ),
                ),

                TextField(
                  controller: controllers['CompanyName'],
                  decoration: InputDecoration(
                    hintText: "Name of Company",
                    enabledBorder: AppStyles.authBorder,
                    focusedBorder: AppStyles.authBorder,
                    border: AppStyles.authBorder,
                    fillColor: Colors.transparent,
                    filled: true,
                  ),
                ),


              ],
            ),
          ),

`

</issue_description>

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


💬 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:03
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 error on scroll for Autocomplete widget Fix external controller disposal causing scroll errors Oct 26, 2025
Copilot AI requested a review from EmilyMoonstone October 26, 2025 12:10
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.

Error on Scroll if controller property is set

2 participants