flutter - 包含空安全库,现在代码未运行
问题描述
我使用了空安全库。现在我遇到了这个问题。请看截图。即使添加了空检查,它也不会。
body: FutureBuilder(
future: allPerson(),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
List list = snapshot.data;
return Card(
child: ListTile(
title: Container(
width: 100,
height: 100,
child: Image.network(
"http://192.168.1.101/image_upload_php_mysql/uploads/${list[index]['image']}"),
),
subtitle: Center(child: Text(list[index]['name'])),
),
);
})
: Center(
child: CircularProgressIndicator(),
);
},
),
谢谢。
解决方案
您可以为数据future
函数的返回值指定类型。snapshot
FutureBuilder<List<dynamic>>(
future: allPerson(),
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) { ...
推荐阅读
- javascript - 我需要添加支付集成我需要知道什么?
- html - Bookdown - 数学中的定理参考?
- java - Mockito 使用“d”验证被测方法的后缀双参数
- maven - 无法使用 testng.xml 执行 Cucumber 功能文件
- python - 如何匹配不同网格网格的值?
- python - UnicodeDecodeError:“utf-8”编解码器无法解码位置 6 中的字节 0xe1:无效的继续字节
- lua - Lua中的循环时间为5分钟间隔
- bash - Bash:变量问题中的嵌套变量
- angular - 您如何将 Angular 项目投入生产?
- ios - 即使在表格视图启用或不启用搜索后,我如何处理清单按钮