我使用这个库的演示,它可以正常工作。但是当我在我的项目中实现时,我在这一行收到错误提示:
Error: Not a constant expression. const AssetImage(snapshot.data[index]),
我的Container
包裹在InkWell
中。
InkWell(
child: Container(
padding:
EdgeInsets.zero,
height: 150,
width: 150,
decoration:
BoxDecoration(
image: DecorationImage(
image: AssetImage(snapshot.data[index]),
fit: BoxFit .fill),
),
),
onTap: () {
print('The value is ' + snapshot .data[index]);
Navigator.push(
context,
MaterialPageRoute(
builder:
(context) =>
const FullScreenWrapper(imageProvider:const AssetImage(snapshot.data[index]), // here the error
)));
},
),
这里是打印的值
该值是/storage/emulated/0/Android/data/xxx/files/Pictures/scaled_1572364487252xxx.jpg
如果我删除const,就会得到其他的错误。
常量声明的参数必须是常量表达式。尝试将参数设置为有效的常量,或使用“new”调用构造函数。
我甚至尝试使用new
但无济于事。
FullScreenWrapper
前面的const
也删掉。 - lyio