flutter - How do i get a loading screen while i fetch images from api?
问题描述
I want a loading screen when i shake screen and 10 more images loads from api.
void initState() {
super.initState();
_shakePlugin = FlutterShakePlugin(
onPhoneShaken: (){
//do stuff on phone shake
setState(() {
count=count+10;
});
},
)..startListening();
}
Future<String> getjsondata() async {
try {
var response = await http.get(
'https://api.unsplash.com/search/photos?per_page=${count}&client_id=TcAQEO3JoMG90U7Rl-YUiDo1x9XbZukzMOMQhxUVCV4&query=${_search}');
setState(() {
var converted = json.decode(response.body);
data = converted['results'];
});
} catch (e) {}
return 'success';
}
Whenever i increment the count by 10,i need a loading widget to show until it fetches the images from api.
解决方案
Use FutureBuilder
to handle the different snapshot conditions and connection states to show different widgets
推荐阅读
- r - ggplot2 的 stat_summary_bin 中的分箱是如何完成的?
- java - 如何通过 mongodb Java 驱动程序 3.4+ 使用 capped collection 添加多个文档?
- javascript - 切换隐藏/显示不适用于子 div
- java - java.nio.file.AccessDeniedException 到 ~/AppData\Local\Temp\unlink-test12695598880278433589.tmp 文件 bt-cli api
- node.js - 排队异步任务
- javascript - Firebase 实时数据库是否有任何“生命周期”事件?
- html - 在 Bootstrap 4 中使行占据全高
- css - Laravel Mix - 当本地主机上的网站不在根文件夹中时,URL 处理工作错误
- database - Visual Studio 2017 显示表数据不起作用
- ios - 强制 iOS 返回新位置?