http - 单击按钮以查看更改时,必须重新加载应用程序(Flutter)

标签 http flutter asynchronous dart async-await

这是我的项目:https://github.com/OstapFilipenko/Picslash

我试图创建一个应用,该应用从unsplash API获取图片并显示这些图片。
首先是调用一个异步函数来获取所有图像并将它们保存在List中。我正在使用ListView.builder来显示它们,并且在listView的末尾,我有一个按钮,该按钮进行API调用并将新图片添加到ListView。

功能:

var newImages = new List<Picture>();
  _getNewPics() async{
  counter++;
  newImages.clear();
  newImages = await API_connection(counter).getPictures();
  allImages.addAll(newImages);
}  

这是按钮:
child: FlatButton(
              child: Text("Load More",
                      style: new TextStyle(
                        color: Colors.white
                      )
                    ),
              onPressed: (){
                _getNewPics();
              },
          ),

问题是,当我启动该应用程序时,什么都没有显示,因此我必须按ctrl + S(重新加载该应用程序),然后才能看到图像,这与单击“加载更多”按钮时必须执行的操作相同。

如果有人可以帮助我,那就太好了:)

最佳答案

一旦出现新图像,就可以将setState()StatefulWidget一起使用来重建小部件。

关于http - 单击按钮以查看更改时,必须重新加载应用程序(Flutter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62214221/

相关文章:

http - 如何使用 apache camel 将消息发送到多个目的地?

firebase - 如何删除 firebase 中的特定节点?

android - 使用-sdk :minSdkVersion 16 cannot be smaller than version 23 declared in library

c++ - 2个 future 之间的依赖

ios - CoreData 完成后 Swift iOS 9 UITableView 重新加载数据

php - HTTP 缓存、用户身份验证和 PHP

internet-explorer - 在 Internet Explorer 中使用同步可插入协议(protocol)的自定义 url 协议(protocol)的最大长度是多少?

android - cameras.isEmpty null flutter

c# - await 在这个函数中做了什么?

javascript - 在for循环中进行同步http调用