-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Steps to reproduce
In DropdownMenuFormField's constructor, we invoke super (which is of type FormField) with a builder that declares the onSelectedHandler function, closing over _DropdownMenuFormFieldState<T>'s didChange:
| final _DropdownMenuFormFieldState<T> state = field as _DropdownMenuFormFieldState<T>; | |
| void onSelectedHandler(T? value) { | |
| field.didChange(value); | |
| onSelected?.call(value); | |
| } |
... and later uses it in the constructor of DropdownMenu:
| onSelected: onSelectedHandler, |
For reference, here is the declaration (on _DropdownMenuFormFieldState) of didChange:
flutter/packages/flutter/lib/src/material/dropdown_menu_form_field.dart
Lines 179 to 184 in 2265d94
| @override | |
| void didChange(T? value) { | |
| super.didChange(value); | |
| _dropdownMenuFormField.onSelected?.call(value); | |
| _updateRestorableController(value); | |
| } |
Note that didChange invokes _dropdownMenuFormField.onSelected?.call(value). Note that onSelectedHandler (linked above), first invokes didChange, then itself invokes onSelected?.call(value).
As a result, the original final ValueChanged<T?>? onSelected; passed in via constructor argument below to DropdownMenuFormField is double-invoked.
| this.onSelected, |
Expected results
onSelected is invoked once when a DropdownMenuEntry is selected within a DropdownMenuFormField.
Actual results
onSelected is invoked twice when a DropdownMenuEntry is selected within a DropdownMenuFormField.
Code sample
N/A
Screenshots or Video
N/A
Logs
N/A
Flutter Doctor output
[!] Flutter (Channel stable, 3.35.1, on macOS 15.6 24G84 darwin-arm64, locale en-US)