这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Feb 20, 2025

Description

This PR introduces DropdownMenuFormField.

Related Issue

Fixes Create DropdownMenuFormField
Fixes Add validator to DropdownMenu

Tests

Adds 41 tests.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Feb 20, 2025
@bleroux bleroux force-pushed the add_dropdownmenuformfield branch 3 times, most recently from 66b728c to 66b1d60 Compare February 20, 2025 14:18
@bleroux bleroux requested a review from justinmc February 21, 2025 18:15
@bleroux
Copy link
Contributor Author

bleroux commented Feb 21, 2025

For the moment only the selected value is considered for the form field, the content of the text field is not considered (no validation when changed), this is because currently the text field is meant to be use to filter and search entries.

@justinmc Do you think we should include the text field content also? It probably makes sense when the DropdownMenu is used as a combobox.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review! Some questions but otherwise this looks good. I think it's valuable to create this FormField for users, thanks for doing it.

super.reset();
_dropdownMenuFormField.onSelected?.call(value);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful to also override restoreState, like TextFormField does?

void restoreState(RestorationBucket? oldBucket, bool initialRestore) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at this, the main problem is that Restoration API works for basic types (String, int, etc) but not for any subclass of Object (until serialization code is provided). And the selected value for a DropdownMenu could be of any type.

I will try to use the restoration API just for the inner text field (more precisely for its text controller) and in restoreState when a value is restored it might possible to check if it matches one of the dropdown menu entries.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah true. Let me know how it goes, it would be nice to have if possible. Also add a test for it if you get it working.

@tina-nova
Copy link

tina-nova commented Mar 30, 2025

For the moment only the selected value is considered for the form field, the content of the text field is not considered (no validation when changed), this is because currently the text field is meant to be use to filter and search entries.

@justinmc Do you think we should include the text field content also? It probably makes sense when the DropdownMenu is used as a combobox.

I'd appreciate this, as the form can be submitted while the text field still has text in it and I'm not sure if a value is even selected (or which value is selected) when submitting

@bleroux bleroux force-pushed the add_dropdownmenuformfield branch from 66b1d60 to 74921f5 Compare March 31, 2025 08:21
@github-actions github-actions bot added the engine flutter/engine related. See also e: labels. label Mar 31, 2025
@bleroux bleroux force-pushed the add_dropdownmenuformfield branch from 74921f5 to 97a94cb Compare March 31, 2025 08:32
@github-actions github-actions bot removed the engine flutter/engine related. See also e: labels. label Mar 31, 2025
@bleroux bleroux force-pushed the add_dropdownmenuformfield branch 2 times, most recently from a9c6889 to ba074b1 Compare April 2, 2025 12:55
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Sounds like there are two comments you're still looking into, but LGTM either way you go with them. Thanks for looking into those.

super.reset();
_dropdownMenuFormField.onSelected?.call(value);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah true. Let me know how it goes, it would be nice to have if possible. Also add a test for it if you get it working.

@bleroux bleroux force-pushed the add_dropdownmenuformfield branch 2 times, most recently from 1818c5d to b1276b7 Compare April 3, 2025 13:05
@bleroux
Copy link
Contributor Author

bleroux commented Apr 17, 2025

Once #166684 will be merged, I will update this PR to add support for restoration API.

github-merge-queue bot pushed a commit that referenced this pull request Apr 17, 2025
## Description

This PR introduces `DropdownMenu.restorationId`.
This value is passed to the inner `TextField.restorationId` which is
required to activate the TextField restoration capability.

## Related Issue

Required for #163721

## Tests

Adds 1 test.
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM with the restorationId and test, thanks for adding that!

@bleroux
Copy link
Contributor Author

bleroux commented Apr 18, 2025

Thanks for the approval.

#166684 was merged, now I have to update this PR to make use of it but also have to leverage RestorableTextEditingController (similarly to how TextFormField use it). My plan is to make this update next week (in fact the code is almost ready but on a computer I don't have access to until the end of next week 😅 ).

ash2moon pushed a commit to ash2moon/flutter that referenced this pull request Apr 21, 2025
## Description

This PR introduces `DropdownMenu.restorationId`.
This value is passed to the inner `TextField.restorationId` which is
required to activate the TextField restoration capability.

## Related Issue

Required for flutter#163721

## Tests

Adds 1 test.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request May 6, 2025
## Description

This PR introduces DropdownMenuFormField.

## Related Issue

Fixes [Create
DropdownMenuFormField](flutter#141941)
Fixes [Add validator to
DropdownMenu](flutter#152131)

## Tests

Adds 41 tests.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 7, 2025
@omar-khaium
Copy link

omar-khaium commented Jun 16, 2025

@bleroux, which channel currently has this Feature ?

@bleroux
Copy link
Contributor Author

bleroux commented Jun 16, 2025

For the moment, it is only on master.
See the commit page: 183b9ea

image

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull request Aug 14, 2025
## Description

This PR introduces `DropdownMenu.restorationId`.
This value is passed to the inner `TextField.restorationId` which is
required to activate the TextField restoration capability.

## Related Issue

Required for flutter#163721

## Tests

Adds 1 test.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
@nebkat
Copy link

nebkat commented Oct 8, 2025

For the moment only the selected value is considered for the form field, the content of the text field is not considered (no validation when changed), this is because currently the text field is meant to be use to filter and search entries.

Is this being tracked somewhere? Currently if you make a selection then type random text there doesn't seem to be an easy way get feedback that the previous selection is no longer valid (except indirectly using the TextEditingController).

I believe there should be an onTextChanged callback, or perhaps even better a requireValidText flag that would call onSelected(null) if the user text does not exactly match one entry.

@bleroux
Copy link
Contributor Author

bleroux commented Oct 8, 2025

Is this being tracked somewhere?

@nebkat I don't think an issue was created to track this. It would be helpful if you can create one and describe the use cases. It would a place to collect feedback and discuss possible solutions.

@nebkat
Copy link

nebkat commented Oct 9, 2025

Is this being tracked somewhere?

@nebkat I don't think an issue was created to track this. It would be helpful if you can create one and describe the use cases. It would a place to collect feedback and discuss possible solutions.

#176753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add validator to DropdownMenu Create DropdownMenuFormField

5 participants