当前位置:网站首页>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']);
}
边栏推荐
- Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
- 官宣出自己的博客了
- Robust Real-time LiDAR-inertial Initialization (Real-time Robust LiDAR Inertial Initialization) Paper Learning
- 【二叉树-中等】2265. 统计值等于子树平均值的节点数
- 2022.8.8 exam sweeps the horse (sweeper) antithesis
- [Red Team] ATT&CK - Auto Start - Registry Run Key, Startup Folder
- PostgreSQL相关语法及指令示例
- flink 12 源码编译及使用idea运行、debug
- Completion of the flag set in 2022
- MySQL: What MySQL optimizations have you done?
猜你喜欢
2022/08/09 学习笔记 (day26) IO流
HACKTHEBOX——Bank
推荐几款好用的MySQL开源客户端,建议收藏
MySQL: Introduction to Logging System | Error Log | Query Log | Binary Log: Bin-log Data Recovery Practice | Slow Log Query
量化交易策略介绍及应用市值中性化选股
【二叉树-困难】124. 二叉树中的最大路径和
Example 047: Functions Swap Variables
实测办公场景下,国产远程控制软件的表现力如何?(技术解析)
plsql 查询数据库操作历史记录(Ctrl + e)
MySQL:日志系统介绍 | 错误日志 | 查询日志 | 二进制日志:bin-log数据恢复实践 | 慢日志查询
随机推荐
Difference Between Data Mining and Data Warehousing
nodejs 时钟案例(fs模块),重复使用fs.writeFile方法,旧内容会被覆盖
WPF 实现更换主题色
GDB command basic parameters
Arcgis进阶篇(1)——安装Arcgis Enterprise,创建sde库
实例043:作用域、类的方法与变量
Database management tool: dynamic read-write separation
【Image Classification】2022-ResMLP
官宣出自己的博客了
liunx PS1 settings
【二叉树-困难】124. 二叉树中的最大路径和
excel高级绘图技巧100讲(二十三)-Excel中实现倒计时计数
【红队】ATT&CK - 自启动 - 利用LSA身份验证包自启动机制
2022.8.8考试区域链接(district)题解
基于误差状态的卡尔曼滤波ESKF
【图像分类】2022-ConvMixer ICLR
【8.8】代码源 - 【不降子数组游戏】【最长上升子序列计数(Bonus)】【子串(数据加强版)】
网页挖矿溯源?浏览器浏览历史查看工具Browsinghistoryview
HRnet
二进制与内存