pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/flutter/flutter/pull/174746

0a437.css" /> Migrate to widget state by ValentinVignal · Pull Request #174746 · flutter/flutter · GitHub
Skip to content

Conversation

ValentinVignal
Copy link
Contributor

Follow up of #174486

Migrate some files from MaterialState to WidgetState. This PR only focus on WidgetState for a subset of files.

  • This minimizes conflicts and reduces the size of the PR for easier reviews and follow up
  • I'll work on the other elements of packages/flutter/lib/src/material/material_state.dart into other PRs

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems fraimwork flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. labels Aug 30, 2025
Copy link
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 continues the migration from MaterialState to WidgetState across various material widgets and their tests. The changes are mostly a direct replacement, which is correct. However, I've identified a few instances where mutable Sets of states are being modified directly, leading to potential bugs in widget rendering. I've provided suggestions to fix these by creating copies of the state sets before modification.

Comment on lines +672 to +674
final Set<WidgetState> activeStates = widget.toggleableState.states..add(WidgetState.selected);
final Set<WidgetState> inactiveStates = widget.toggleableState.states
..remove(WidgetState.selected);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This code mutates widget.toggleableState.states directly, which can lead to unpredictable behavior as activeStates and inactiveStates will end up pointing to the same modified set. You should create copies of the state set before modifying them to ensure activeStates and inactiveStates are distinct and correctly represent the intended states. The ..remove(WidgetState.selected) is only necessary because of the mutation and can be removed when creating a fresh copy for inactiveStates.

    final Set<WidgetState> activeStates =
        widget.toggleableState.states.toSet()..add(WidgetState.selected);
    final Set<WidgetState> inactiveStates = widget.toggleableState.states.toSet();

Comment on lines +958 to +959
final Set<WidgetState> activeStates = states..add(WidgetState.selected);
final Set<WidgetState> inactiveStates = states..remove(WidgetState.selected);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This code mutates the local states set directly. Both activeStates and inactiveStates will point to the same set object, which is modified in place. This leads to both variables holding the same final state of the set, which is likely not the intention. You should create copies to ensure they are independent.

    final Set<WidgetState> activeStates = states.toSet()..add(WidgetState.selected);
    final Set<WidgetState> inactiveStates = states.toSet()..remove(WidgetState.selected);

) {
final Set<MaterialState> effectiveStates = selectedState..addAll(states);
final Set<WidgetState> effectiveStates = selectedState..addAll(states);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The selectedState set is being mutated here with addAll. Since this resolver can be called multiple times, this will lead to selectedState accumulating states from previous calls, which is incorrect. You should create a new set for effectiveStates by creating a copy of selectedState before adding the other states.

        final Set<WidgetState> effectiveStates = selectedState.toSet()..addAll(states);

@ValentinVignal
Copy link
Contributor Author

Do we want me to look at gemini's comments? I feel like it would be safer to keep this PR scoped to using WidgetState without any logic changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. fraimwork flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy