它显示来自网络的url图像,但不显示来自assts的图像,因为我正在尝试访问assers的图像。
从我的flutter项目中获取的图像列表:
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,),
],
),
),
您必须在列表中设置网址,而不是图像小部件。将您的列表更改为:
final List imgList = [
'assests/GL.png',
'assests/GL.png',
'assests/GL.png',
];