Description
I have two FormBuilderDropdowns which depend on each other, one is for categories and the other is for sub categories. When I change category then sub categories are loaded. This works fine as long as there is no selected subcategory but if I select a category, then select one of its sub categories it throws the following exception:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building FormField-[LabeledGlobalKey<FormFieldState>#3f353](dirty, dependencies: [_FormScope], state: FormFieldState#68c0b):
There should be exactly one item with [DropdownButton]'s value: {id: 3ebc51ba390511eab6a06b0f2e982c39, name: Self Referral, code: 0002, category_id: 3eb329ef390511eab6a029aa47757af9, category_name: User Fee, active: 1, deleted: 0}.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 805 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem item) {
return item.value == value;
}).length == 1'
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
The relevant error-causing widget was:
FormBuilderDropdown-[<'visit_subcategory'>] file:///home/kasanga/AndroidStudioProjects/mobile/lib/dialogs/client_dialog.dart:119:19
When the exception was thrown, this was the stack:
#2 new DropdownButton (package:flutter/src/material/dropdown.dart:805:15)
#3 _FormBuilderDropdownState.build. (package:flutter_form_builder/src/fields/form_builder_dropdown.dart:118:26)
#4 FormFieldState.build (package:flutter/src/widgets/form.dart)
#5 StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)
#6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
...
═════════════════════
How can I clear the subcategories drop down's value when the categories drop down value changes?