Skip to content

Commit 8475b99

Browse files
authored
Merge pull request #347 from AhmedLSayed9/form_fields_on_change_call_back
Form fields onChange callback should be called on reset [Flutter core]
2 parents e93fb69 + 112c172 commit 8475b99

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix errorStyle has no effect for DropdownButtonFormField2, closes #327.
44
- DropdownRoutePage should dispose the created ScrollController [Flutter core].
55
- Remove 'must be non-null' and 'must not be null' comments [Flutter core].
6+
- Form fields onChange callback should be called on reset [Flutter core].
67

78
## 3.0.0-beta.21
89

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,13 @@ class DropdownButtonFormField2<T> extends FormField<T> {
11061106
}
11071107

11081108
class _DropdownButtonFormFieldState<T> extends FormFieldState<T> {
1109+
DropdownButtonFormField<T> get _dropdownButtonFormField =>
1110+
widget as DropdownButtonFormField<T>;
1111+
11091112
@override
11101113
void didChange(T? value) {
11111114
super.didChange(value);
1112-
final DropdownButtonFormField2<T> dropdownButtonFormField =
1113-
widget as DropdownButtonFormField2<T>;
1114-
assert(dropdownButtonFormField.onChanged != null);
1115-
dropdownButtonFormField.onChanged!(value);
1115+
_dropdownButtonFormField.onChanged!(value);
11161116
}
11171117

11181118
@override
@@ -1122,4 +1122,10 @@ class _DropdownButtonFormFieldState<T> extends FormFieldState<T> {
11221122
setValue(widget.initialValue);
11231123
}
11241124
}
1125+
1126+
@override
1127+
void reset() {
1128+
super.reset();
1129+
_dropdownButtonFormField.onChanged!(value);
1130+
}
11251131
}

0 commit comments

Comments
 (0)