@@ -225,6 +225,47 @@ void main() {
225225 expect (formValue (widgetName), equals (2 ));
226226 });
227227 });
228+ testWidgets ('Should reset to null when call reset' , (tester) async {
229+ const widgetName = 'dropdown_field' ;
230+
231+ // Define the initial and updated items for the dropdown
232+ const List <DropdownMenuItem <int >> initialItems = [
233+ DropdownMenuItem (value: 1 , child: Text ('Option 1' )),
234+ DropdownMenuItem (value: 2 , child: Text ('Option 2' )),
235+ ];
236+
237+ final testWidget =
238+ FormBuilderDropdown (name: widgetName, items: initialItems);
239+ await tester.pumpWidget (buildTestableFieldWidget (testWidget));
240+
241+ formKey.currentState? .patchValue ({widgetName: 1 });
242+ await tester.pumpAndSettle ();
243+ formKey.currentState? .reset ();
244+
245+ expect (formKey.currentState? .instantValue, {widgetName: null });
246+ });
247+ testWidgets ('Should reset to initial when call reset' , (tester) async {
248+ const widgetName = 'dropdown_field' ;
249+ const initialValue = {widgetName: 1 };
250+
251+ // Define the initial and updated items for the dropdown
252+ const List <DropdownMenuItem <int >> initialItems = [
253+ DropdownMenuItem (value: 1 , child: Text ('Option 1' )),
254+ DropdownMenuItem (value: 2 , child: Text ('Option 2' )),
255+ ];
256+ final testWidget =
257+ FormBuilderDropdown (name: widgetName, items: initialItems);
258+ await tester.pumpWidget (buildTestableFieldWidget (
259+ testWidget,
260+ initialValue: initialValue,
261+ ));
262+
263+ formKey.currentState? .patchValue ({widgetName: 2 });
264+ await tester.pumpAndSettle ();
265+ formKey.currentState? .reset ();
266+
267+ expect (formKey.currentState? .instantValue, equals (initialValue));
268+ });
228269}
229270
230271class MyTestWidget <T > extends StatefulWidget {
0 commit comments