Ton*_*ony 8 assets photo dart flutter
我使用了这个库中的演示,它工作得很好。但是当我在我的项目中实施时,我在这一行出现错误
错误:不是常量表达式。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
)));
},
),
Run Code Online (Sandbox Code Playgroud)
这里的打印值
值为/storage/emulated/0/Android/data/xxx/files/Pictures/scaled_1572364487252xxx.jpg
如果我删除const,我会收到其他错误
常量创建的参数必须是常量表达式。尝试使参数成为有效的常量,或使用“new”来调用构造函数。
我什至尝试使用new
但无济于事。
lyi*_*yio 20
在这里,const AssetImage(snapshot.data[index])
您正在使用const
构造函数。编译器需要一个编译时常量并且抱怨,因为你传入的参数不是常量而是依赖于snapshot.data
.
如果您只是删除const
关键字,它应该编译没有错误。
归档时间: |
|
查看次数: |
9773 次 |
最近记录: |