[英]I am getting a flutter type error 'Response' is not a subtype of 'FutureOr<String>'
[英]I am getting error while using package CarouselSlider it display error type 'Image' is not a subtype of type 'String' in flutter
它显示来自网络的 url 图像,但不显示来自资产的图像,因为我正在尝试访问来自资产的图像。
我的 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,),
],
),
),
您必须在列表中设置 url 而不是 Image Widgets。 将您的列表更改为:
final List imgList = [
'assests/GL.png',
'assests/GL.png',
'assests/GL.png',
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.