Widget build(BuildContext context) {
return GestureDetector(
onTap: clickCallback,
child: Container(
child: ,
decoration: BoxDecoration(
color: Colors.red,
image: DecorationImage(
image: Image.network(lessons.image!),
fit: BoxFit.fill, // 完全填充
),
)),
);
}
给Container设置背景的时候发生错误:
The argument type 'Image' can't be assigned to the parameter type 'ImageProvider<Object>
解决方式:
不要使用Image.network,使用NetworkImage加载图片
初学flutter还不明白原理。
修改后的代码如下:
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: clickCallback,
child: Container(
child: ,
decoration: BoxDecoration(
color: Colors.red,
image: DecorationImage(
image: NetworkImage(lessons.image!) ,
fit: BoxFit.fill, // 完全填充
),
)),
);
}