我用这个演示
library
而且效果很好。
但是当我在我的项目中实现时,我在这条线上得到了错误
错误:不是常量表达式。常量
AssetImage(快照数据[索引]),
我的
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
)));
},
),
这里是印刷值
价值是
/存储/模拟/0/Android/data/xxx/files/Pictures/scaled_1572364487252xxx.jpg
如果我移除
常量
,我得到其他错误
常量创建的参数必须是常量表达式。尝试
使参数成为有效常量,或使用“new”调用
构造器。
我甚至试着用
new
但没用。