Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird random swipe when itemCount is dynamic #285

Open
eggysudianto opened this issue Nov 8, 2021 · 1 comment
Open

weird random swipe when itemCount is dynamic #285

eggysudianto opened this issue Nov 8, 2021 · 1 comment

Comments

@eggysudianto
Copy link

eggysudianto commented Nov 8, 2021

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)),
                          ),
                        ),
                    ),
@eggysudianto eggysudianto changed the title random swipe weird random swipe when itemCount is dynamic Nov 8, 2021
@CuiChuping
Copy link

CuiChuping commented Mar 6, 2022

Have you found a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants