简体   繁体   English

如何制作从API接收响应的进度条?

[英]How to make progress bar for receiving response from API?

while receiving data from API to flutter app it takes time to receive.在从 API 接收数据到 Flutter 应用程序时,它需要时间来接收。 How to make a progress bar to load until the JSON data is received to the flutter app and move to next Screen of the app.如何使进度条加载,直到 JSON 数据接收到 Flutter 应用程序并移动到应用程序的下一个屏幕。

I'm not using ListView.Builder.我没有使用 ListView.Builder。 Instead I use it for texts, dropdown and other things also.相反,我也将它用于文本、下拉菜单和其他内容。

You could use a FutureBuilder widget, as shown in the cookbook for retrieving and displaying data :您可以使用 FutureBuilder 小部件,如用于检索和显示数据食谱所示:

FutureBuilder<Album>(
  future: futureAlbum,
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      return Text(snapshot.data.title);
    } else if (snapshot.hasError) {
      return Text("${snapshot.error}");
    }

    // By default, show a loading spinner.
    return CircularProgressIndicator();
  },
);

This widget allows you to build your layout with information about the data your are loading and the status of the load itself.此小部件允许您使用有关正在加载的数据和加载本身的状态的信息来构建布局。

For the future: parameter, give him your http.get request.对于future:参数,给他你的http.get请求。

In the builder: param, give it an anonymous function that builds the content you want to display.builder: param 中,给它一个匿名函数来构建你想要显示的内容。 In said closure, you can rely on the snapshot to know wether the data has finished downloading ( snapshot.hasData ) or if there was an error downloading ( snapshot.hasError ).在上述闭包中,您可以依靠snapshot来了解数据是否已完成下载( snapshot.hasData )或下载是否有错误( snapshot.hasError )。 To display the progress bar you asked for, you can infer the status : if the snapshot has no data nor any error, therefore it is loading and you return you progress bar to the user.要显示您要求的进度条,您可以推断状态:如果快照没有数据或任何错误,则它正在加载,您将进度条返回给用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 API ajax请求的进度栏仅在从API获得响应后才开始加载 - Progress Bar for API ajax request starts loading only after getting response from API 如何在颤动中使选项卡和选项卡栏视图动态化,以便它能够响应来自 api 的响应? - How do I make a tab and tab bar view dynamic in flutter so that it will ha on the response from an api? 使用Python API创建产品时未收到Shopify的响应 - Not Receiving a Response from Shopify When Creating a Product Using Python API Wordpress通过来自第三方API的响应URL接收有效负载 - Wordpress receiving a payload via a response url from third party API 在收到来自 API 的响应后尝试将元素添加到数组 - Trying to add elements to an array after receiving an response from an API 发出发布请求时,我没有收到来自 API 的响应 - I'm not receiving response from API when making a post request 与Fit Api一起使用的进度条 - Progress Bar working with Fit Api 如何重定向到从 API php 返回响应的链接? - How to make redirecte to link, which return response from API php? 如何通过API获取正在运行的jenkins作业的进度条数据 - how to get progress bar data for a running jenkins job through the API 如何在前端实现一个进度条,显示有关 API 调用进度的信息? - How can I implement a progress bar on front-end showing the information about an API call progress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM