当前位置:网站首页>flutter异步
flutter异步
2022-08-10 02:37:00 【氤氲息】
getData() async {
//async关键字声明该函数内部有代码需要延迟执行
return await http.get(Uri.encodeFull(url), headers: {
"Accept": "application/json"}); //await关键字声明运算为延迟执行,然后return运算结果
}
如果需要调用getData方法,要为这个给data赋值的语句加一个async函数的包装:
String data;
setData() async {
data = await getData(); //getData()延迟执行后赋值给data
}
await关键字必须在async函数内部使用
调用async函数必须使用await关键字
Future.value():返回一个指定值的Future
例子
列表的缓存一般是放在本地数据库中
Future<String?> _getConfigData() async {
//Future<String?>可以省略的
print('getVipHead=====_getConfigData====');
if (!DatabaseUtil.isDatabaseReady) {
DatabaseUtil.initDatabase();
}
var data = await DatabaseUtil.queryHttp(//从数据库里面查询数据,使用异步操作,async和await
DatabaseUtil.database!,
NetUtils.getCacheKeyFromPath(
Api.BUSINESS_BASE_API + Api.API_GETCONFIG, {
}));
// print('getVipHead=====_getConfigData====${json.decoder.convert(data.first['value'])}');
return json.decoder.convert(data.first['value']);
}
边栏推荐
- Chapter 21 Source Code File REST API Reference (3)
- web crawler error
- 官宣出自己的博客啦
- “双枪”木马病毒的进化史
- mock模拟,skip,skipif,mark分类
- 论文理解:“PIAT: Physics Informed Adversarial Training for Solving Partial Differential Equations“
- 【Image Classification】2022-ConvMixer ICLR
- QT modal dialog and non-modal dialog learning
- Introduction and application of quantitative trading strategies
- Error state based Kalman filter ESKF
猜你喜欢
【二叉树-中等】2265. 统计值等于子树平均值的节点数
想要避免After Effects渲染失败的问题,5个小技巧必看
量化交易策略介绍及应用市值中性化选股
实测办公场景下,国产远程控制软件的表现力如何?(技术解析)
[Red Team] ATT&CK - Self-starting - Self-starting mechanism using LSA authentication package
ArcGIS Advanced (1) - Install ArcGIS Enterprise and create an sde library
【Image Classification】2022-ConvMixer ICLR
ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
HackTheBox——Beep
使用curl指令发起websocket请求
随机推荐
2022.8.9 Exam Cube Sum--1100 Question Solutions
nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
2022.8.8 Exam Travel Summary
what is a microcontroller or mcu
Data Governance (5): Metadata Management
是什么让训练综合分类网络艰苦?
【Kali安全渗透测试实践教程】第6章 密码攻击
跨站请求伪造(CSRF)攻击是什么?如何防御?
【二叉树-中等】2265. 统计值等于子树平均值的节点数
Robust Real-time LiDAR-inertial Initialization(实时鲁棒的LiDAR惯性初始化)论文学习
2022.8.8考试清洁工老马(sweeper)题解
flex 的 三个参数:flex-grow、flex-shrink、flex-basis
[Semantic Segmentation] 2022-HRViT CVPR
Example 047: Functions Swap Variables
HRnet
实测办公场景下,国产远程控制软件的表现力如何?(技术解析)
HRnet
第二十一章 源代码文件 REST API 参考(三)
高精度加法
storage of data in memory