【发布时间】:2020-03-09 00:05:25
【问题描述】:
我使用来自library 的演示,它运行良好。 但是当我在我的项目中实现时,我在这一行得到了错误
错误:不是常量表达式。常量 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,但无济于事。
【问题讨论】: