-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Future builder for dropdown menu items #321
Comments
I am looking to do this too - any assistance would be great. |
you would need to wrap your FormBuilder in FutureBuilder // normal to use a list
List _catsList;
// your future list
Future<List> _cats;
Future<List> _getCats() async{
var res = await Dio().get('http://wazner.test/api/cat');
return res.data;
} @override
void initState() {
_cats = _getCats();
super.initState();
}
FutureBuilder(
future: _cats,
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.hasData){
_catsList = snapshot.data;
return FormBuilder(
// your logic
// includes your dropdown menu items
FormBuilderDropdown(
items: _catsList.map((item) => DropdownMenuItem(
value: item['id'],
child: Text("${item['name']}")
)).toList(),
),
)
}
return CircularProgressIndicator();
},
),
|
Thanks much for the help! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are there plans to allow a Future to populate the dropdown values? An example is retrieving a list of countries and states from a REST API and populating them in the dropdown menu. If this can already be done, please let me know how. Thanks for your help.
The text was updated successfully, but these errors were encountered: