flutter - 我在使用包 CarouselSlider 时遇到错误,它显示错误类型“图像”不是颤振中“字符串”类型的子类型
问题描述
它显示来自网络的 url 图像,但不显示来自 assests 的图像,因为我正在尝试从 assests 访问图像。
我的颤振项目中来自资产的图像列表:
int _current = 0;
final List imgList = [
Image.asset('assests/GL.png'),
Image.asset('assests/GL.png'),
Image.asset('assests/GL.png'),
];
CarouselSlider 中的代码
CarouselSlider(
height: 200,
initialPage: 0,
enlargeCenterPage: true,
autoPlay: true,
reverse: false,
enableInfiniteScroll: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 2000),
pauseAutoPlayOnTouch: Duration(seconds: 10),
scrollDirection: Axis.horizontal,
onPageChanged: (index){
setState(() {
_current = index;
});
},
items: imgList.map((imgUrl){
return Builder(
builder: (BuildContext context){
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(color: Colors.green),
child: Image.assest(imgUrl,fit:BoxFit.fill),//error line in code
);
},
);
}).toList(),),
SizedBox(height: 20,),
],
),
),
解决方案
您必须在列表中设置 url 而不是 Image Widgets。将您的列表更改为:
final List imgList = [
'assests/GL.png',
'assests/GL.png',
'assests/GL.png',
];
推荐阅读
- javascript - 通过js向上更改手风琴箭头
- swift - Can I render the same SKScene to two different views simultaneously?
- angular - 想以角度改变可重用嵌套组件的样式
- r - 无法更改图例框中的文本标签并使用 ggplot 在图例中显示不同的颜色
- android - Groupie 适配器中的 SetOnItemClickListener 不起作用
- typescript - 如何从带有变量的联合类型中选择类型
- python - Float16 在 numpy 中比 Float32 和 Float64 慢得多
- r - 将索引和值列表转换为矩阵
- sql - 如何编写具有多个连接的 linq
- shell - shell中的-lt和<有什么区别?