flutter-carousel-pro icon indicating copy to clipboard operation
flutter-carousel-pro copied to clipboard

Image onTap

Open Invincible1996 opened this issue 6 years ago • 12 comments

When I want to click on the image to another page, I don't know how to do.

Invincible1996 avatar Oct 28 '18 15:10 Invincible1996

@sinceyoyo currently it's not possible to set onTap for every image, but instead you can wrap whole your carousel in a InkWell or GestureDetector.

InkWell(
  onTap: () {
    // Do something here
  },
  child: Carousel(
    images: [
      // ...
    ],
  ),
),

tje3d avatar Dec 04 '18 19:12 tje3d

@sinceyoyo currently it's not possible to set onTap for every image, but instead you can wrap whole your carousel in a InkWell or GestureDetector.

InkWell(
  onTap: () {
    // Do something here
  },
  child: Carousel(
    images: [
      // ...
    ],
  ),
),

How to access current image index in the carousel? For example, when I tap the carousel I want it to show current image in fullscreen...

anisalibegic avatar Dec 07 '18 14:12 anisalibegic

Has this issue been resolved? (i.e, getting the index of the current image).

iesmail3 avatar Feb 11 '19 08:02 iesmail3

I made a PR but it seems that author does not care.

anisalibegic avatar Feb 11 '19 08:02 anisalibegic

Do you know of any other carousel plugin that supports this feature?

iesmail3 avatar Feb 11 '19 08:02 iesmail3

Copy the source code of this plugin and add it to your project. Then see what I have done in my PR and add those changes to the file you downloaded. Then remove the plugin from pubspec.yaml and import the file you previously created.

anisalibegic avatar Feb 11 '19 08:02 anisalibegic

This is how i was able to make it happen without copying the source code in my project and just using it as an package.

child: new Carousel(
                    images: _listBannerImages(),
}

my _listBannerImages() was like:

_listBannerImages() {
    var bannerImages = [];
    for (var image in banners) {
      bannerImages.add(new GestureDetector(
        onTap: (){
          print(image.url);
        },
        child : Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: NetworkImage(image.image),
                  fit: BoxFit.cover)),
          height: 220.0,
          width: MediaQuery.of(context).size.width,
        ),
      ));
    }
    return bannerImages;
  }

and this did the trick. Now i am able to add onTap actions to it.

Hope this helps others as well

baltejsingh88 avatar Feb 12 '19 15:02 baltejsingh88

As this project is not actively maintained, i suggest you guys to try https://pub.dartlang.org/packages/flutter_swiper which is really powerful.

tje3d avatar Feb 12 '19 15:02 tje3d

This is how i was able to make it happen without copying the source code in my project and just using it as an package.

child: new Carousel(
                    images: _listBannerImages(),
}

my _listBannerImages() was like:

_listBannerImages() {
    var bannerImages = [];
    for (var image in banners) {
      bannerImages.add(new GestureDetector(
        onTap: (){
          print(image.url);
        },
        child : Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: NetworkImage(image.image),
                  fit: BoxFit.cover)),
          height: 220.0,
          width: MediaQuery.of(context).size.width,
        ),
      ));
    }
    return bannerImages;
  }

and this did the trick. Now i am able to add onTap actions to it.

Hope this helps others as well

Keep in mind that this creates GestureDetector for every photo which is not that great for performance...

anisalibegic avatar Feb 12 '19 20:02 anisalibegic

where do I add the images using urls? I tried put a list of image urls in the var bannerImages = [ url1, url2, url3 ];

and i got a errors on the GestureDector .... What do I do?

Parables avatar Feb 20 '19 18:02 Parables

Could you please show a screenshot or provide the codes in full? Errors found:

  1. banners is undefined
  2. The argument type 'GestureDetector' can't be assigned to the parameter type 'NetworkImage'.

Parables avatar Feb 20 '19 18:02 Parables

This is how i was able to make it happen without copying the source code in my project and just using it as an package.

child: new Carousel(
                    images: _listBannerImages(),
}

my _listBannerImages() was like:

_listBannerImages() {
    var bannerImages = [];
    for (var image in banners) {
      bannerImages.add(new GestureDetector(
        onTap: (){
          print(image.url);
        },
        child : Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: NetworkImage(image.image),
                  fit: BoxFit.cover)),
          height: 220.0,
          width: MediaQuery.of(context).size.width,
        ),
      ));
    }
    return bannerImages;
  }

and this did the trick. Now i am able to add onTap actions to it.

Hope this helps others as well

Hi man, Tks!!!!!!!!!!

brunoa2a avatar Oct 26 '19 23:10 brunoa2a