flutter_swiper
flutter_swiper copied to clipboard
weird random swipe when itemCount is dynamic
UPDATED
this case only if itemCount: dataBanner.length,, but if itemCount: 8 it's normal
this updated code
List<ResultBanner> dataBanner = [];
@override
void initState() {
super.initState();
refresh();
}
Future<void> refresh() async {
getDataBanner();
return;
}
void getDataBanner() {
dataBanner = [];
BannerViewModel().getBanner().then((value) {
if(value != "no data") {
setState(() {
dataBanner = value.result;
});
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: RefreshIndicator(
onRefresh: refresh,
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
expandedHeight: 200,
elevation: 0,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: Positioned(
top: 0,
height: 200,
right: 0,
left: 0,
child:Swiper(
itemBuilder: (BuildContext context,
int index) {
return new Image.network(
"http://via.placeholder.com/288x188",
fit: BoxFit.fill,
);
},
// itemCount: 8, // THIS CODE RUN NORMAL
itemCount: dataBanner.length // THIS CODE LIKE MY VIDEO
pagination: const SwiperPagination(
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
color: Colors.grey,
activeColor: Color(0xff38547C)),
),
),
),
),
),
]
)
)
);
}
I am want to show swiper in home page and event page
when swiper show in homepage it's normal. but when I navigate to eventpage, the swiper just do random swipe (don't know will stop in where index) like my video, how to start from first index?
https://i.stack.imgur.com/VMabS.gif
the code in homepage and eventpage is same code, only have 1 code
this part of my code
Positioned(
top: bannerTop,
height: carouselHeight,
right: 0,
left: 0,
child:Swiper(
autoplay: widget.dataBanner.length==1 ? false : true,
physics: widget.dataBanner.length==1 ? const NeverScrollableScrollPhysics() : null,
autoplayDelay: widget.dataBanner.length==1 ? 0 : 10000,
itemBuilder: (BuildContext context,
int index) {
return InkWell(
// onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => MyWebview(url: web_promo+"&kd="+dataPromo[index].id, statusAppbar: true, webMenu: web_menu_promo)),
// );
// },
child: Card(
margin: const EdgeInsets.only(left: 0, right: 0, bottom: 25),
child: (
ClipRRect(
child: (
CachedNetworkImage(
imageUrl: urlPrefixImages+widget.dataBanner[index].SliderImage,
fit: BoxFit.fill,
placeholder: (context, url) => Image.memory(bytes,fit: BoxFit.cover,),
errorWidget: (context, url, error) => const Icon(Icons.error),
)
)
)
)
),
);
},
itemCount: widget.dataBanner.length,
viewportFraction: 1,
scale: 1,
pagination: const SwiperPagination(
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
color: Colors.grey,
activeColor: Color(0xff38547C)),
),
),
),
Have you found a solution?