1. flutter_swiper をコンテナでラップする必要がある
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. 各デバイスでのカルーセル画像のサイズの歪みを回避する
AspectRatio(aspectRatio: 20/9)
3. インターフェースでカルーセル画像を取得する際に発生する一連のエラー
Flutter Swiperはウィジェットリストを内部に持つカルーセルコンポーネントですが、ウィジェットリストの数が変化した際にこのような異常事態が発生し、カルーセルがスライドしなくなったり、レッドスクリーンなどのエラーが発生したりすると、
ScrollController not attached to any scroll views.
解決
SwiperにLocalKeyを追加することで解決できますが、ここではLocalKeyに属するUniqueKeyを追加しました。
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,
),
)