_formKey.currentState.fields['name'].currentState.value : not working
Did you try this?
_formKey.currentState.value['name']
I just tried it but not achieving what I am trying to do here: Change the item list on the second formbuilder based on the value of the first one. The code below
FormBuilderSearchableDropdown(
name: 'Category',
items: EventItemsList.category,
initialValue: 'Choose',
),
FormBuilderSearchableDropdown(
initialValue: 'Music',
name: 'Subcategory',
items: _formKey.currentState.value['Category'] == 'Music'
? EventItemsList.music_sub_category
: [],
),
How about using the onChanged property to create a new list with values that match the category?
@andrewzakhartchouk example code please
Can't really come up with a solution, but I would suggest to try using setState() and/or Provider to change the items of the 'Subcategory' field.
UPDATE: @angwandi I put some time into it, and solidified my knowledge of states in the progress.
subItems List for the Subcategory field to refer to, the changeSub() function to modify subItems, and asearchableDropdown Widget, all before the build() Widget.class Form extends StatefulWidget {
@override
_FormState createState() => _FormState();
}
class _Form extends State<DailyReport> {
final GlobalKey<FormBuilderState> _formKey =
GlobalKey<FormBuilderState>();
List subItems = [];
void changeSub(item) {
if (item == 'Music') {
setState(() {
subItems = ['Pop', 'Rock', 'Blues'];
});
} else {
setState(() {
subItems = ['Fruits', 'Veg', 'Meat'];
});
}
}
Widget searchableDropdown(List items) {
print(items);
return FormBuilderSearchableDropdown(
name: 'subcategory',
items: items,
);
}
@override
Widget build(BuildContext context) {}
FormBuilderSearchableDropdown labelled 'category', use the onChanged property to call changeSub(), which modifies the List that the 'subcategory' Searchable Dropdown uses.FormBuilderSearchableDropdown(
name: 'category',
items: ['Music', 'Food'],
onChanged: (item) => changeSub(item)
),
searchableDropdown(subItems)
Hope this is what you were looking for.
Thanks @andrewzakhartchouk. Works like a charm
Most helpful comment
Can't really come up with a solution, but I would suggest to try using
setState()and/orProviderto change the items of the 'Subcategory' field.UPDATE: @angwandi I put some time into it, and solidified my knowledge of states in the progress.
subItemsList for the Subcategory field to refer to, thechangeSub()function to modifysubItems, and asearchableDropdownWidget, all before the build() Widget.FormBuilderSearchableDropdownlabelled 'category', use theonChangedproperty to callchangeSub(), which modifies the List that the 'subcategory' Searchable Dropdown uses.Hope this is what you were looking for.