1. flutter_swiper must be wrapped in container
Container(
child:
AspectRatio(
aspectRatio: 20/9,
child: Swiper(
key: UniqueKey(),
itemBuilder: (BuildContext context, int index) {
return new Image.network(
_Swiperlist[index]["path"].length>0?_Swiperlist[index]["path"]:"https://kt-1301681474.cos.ap-shanghai.myqcloud.com/app/rot/lbt_20200425181036.png",
fit: BoxFit.fill,
);
},
itemCount: _Swiperlist.length,
viewportFraction: 0.8,
scale: 0.9,
),
)
)
2. Avoid distortion of the size of the carousel image on each device
AspectRatio(aspectRatio: 20/9)
3. A series of errors caused by obtaining the carousel image in the interface
Flutter Swiper is a carousel component that contains a Widget List inside. When the number of the Widget List changes, if an abnormal situation like this occurs, causing the carousel not to slide or other errors such as red screens,
ScrollController not attached to any scroll views.
Solution
It can be solved by adding a LocalKey to Swiper. I added a UniqueKey here, which belongs to a LocalKey
AspectRatio(
aspectRatio: 20/9,
child: Swiper(
key: UniqueKey(),
itemBuilder: (BuildContext context, int index) {
return new Image.network(
_Swiperlist[index]["path"].length>0?_Swiperlist[index]["path"]:"https://kt-1301681474.cos.ap-shanghai.myqcloud.com/app/rot/lbt_20200425181036.png",
fit: BoxFit.fill,
);
},
itemCount: _Swiperlist.length,
viewportFraction: 0.8,
scale: 0.9,
),
)