如何在下拉菜单中显示来自API的数据
我需要在下拉列表中显示来自API获取请求的数据,从下拉菜单中选择项目时,我需要将所选项目的ID保存到变量中。
这是URL“ https://reqres.in/api/users?page=1
”。
我已经检查了其他帖子,但似乎语法发生了很大变化。
我是新来的扑朔迷离。
从上面的URL中,我需要将“数据”阵列保存到列表中。
I need to display data from an API get request in a dropdown, and when selecting a item from the drop down menu I need to save the id of the selected item into a variable.
Here is the URL "https://reqres.in/api/users?page=1
".
I have checked other posts already, but seems like the syntax changed a lot.
I am new to flutter.
From the above URL, I need the "data" array saved into a list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 futornbuilder 下拉准备就绪了。
下面的代码将解决问题。还要查看 dartpad 的实时演示。
屏幕截图
JSON响应来自 https:// reqres.in/api/users?page=1
You can use FutureBuilder to wait for the API to complete and then show that the dropdown is ready.
The code below will do the trick. Take a look also at the live demo on DartPad.
Screenshots
JSON response from https://reqres.in/api/users?page=1