Carousel Image Slider In Flutter Example

In this tutorial we will learn how to create an image slider in flutter by loading an image from the URL. To show the images in the slider we will use the carousel slider API from flutter dev website.

What is a Carousel Image Slider In Flutter?

Sometimes we want to show images in moving form, it can be from left to right or up to down. You can see these types of dynamic image sliders in amazon, flipkart or many other shopping or entertainment websites or apps.

image slider in flutter
image slider in flutter

Add The Following Dependency

Add the following dependency in your pubspec.yaml file and click on pub get. 

dev_dependencies:
  flutter_test:
    sdk: flutter
  carousel_slider: ^4.0.0

Create A List Of Images

I am directly using the URL of images. You can get your images from a server like API. There is no big difference between them. We only needed the URL. Following is the list of URLs of images you can use by copy and paste in your code.

final List<String> imageList = ["https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80",
  'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
  'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
  'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80'];

Import The Flutter Carousel Image Slider Library In Flutter Class

Import the carousel library in your class where you are using the Carousel Image slider.

import 'package:carousel_slider/carousel_slider.dart';

Widget For Image Slider

Use Following widget in your flutter project class to create a dynamic image slider. You can manage it by wrapping Column, Row, Container or other widget for any type style. Please note that I wrapped it inside Container for better look and margin.

Container(
  margin: EdgeInsets.all(15),
  child: CarouselSlider.builder(
    itemCount: imageList.length,
    options: CarouselOptions(
      enlargeCenterPage: true,
      height: 300,
      autoPlay: true,
      autoPlayInterval: Duration(seconds: 3),
      reverse: false,
      aspectRatio: 5.0,
    ),
    itemBuilder: (context, i, id){
      //for onTap to redirect to another screen
      return GestureDetector(
        child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(15),
            border: Border.all(color: Colors.white,)
        ),
          //ClipRRect for image border radius
          child: ClipRRect(
            borderRadius: BorderRadius.circular(15),
            child: Image.network(
              imageList[i],
            width: 500,
            fit: BoxFit.cover,
            ),
          ),
        ),
        onTap: (){
          var url = imageList[i];
          print(url.toString());
        },
      );
    },
  ),
),

I used the GestureDetector() widget for moving into another screen by clicking on a particular image.

You can learn more about this image slider from pub.dev website. There are many other sliders available for your desire. You can go by clicking here.

Please do comment if you like this tutorial even if you find any issue in this code.

Please also learn more flutter and android tutorials which will improve your development skills.


close

Don’t miss new tips!

We don’t spam! Read our [link]privacy policy[/link] for more info.

68 thoughts on “Carousel Image Slider In Flutter Example”

  1. Pingback: https://canadianpharmaceuticalsonline.home.blog/

  2. Pingback: reallygoodemails.comonlineviagra

  3. Pingback: viagraonline.estranky.skclankyviagra-without-prescription.html

  4. Pingback: viagraonlineee.wordpress.com

  5. Pingback: where to buy viagra online

  6. Pingback: https://viagraonlinee.livejournal.com/492.html

  7. Pingback: buy viagra online no prescription

  8. Pingback: buy viagra online

  9. Pingback: https://www.kadenze.com/users/canadian-pharmaceuticals-for-usa-sales

  10. Pingback: linktr.eecanadianpharmaceuticalsonline

  11. Pingback: disqus.comhomeforumcanadian-pharmaceuticals-online

  12. Pingback: 500px.compcanadianpharmaceuticalsonline

  13. Pingback: https://dailygram.com/index.php/blog/1155353/we-know-quite-a-bit-about-covid-19/

  14. Pingback: northwest pharmacy canada

  15. Pingback: 500px.complistofcanadianpharmaceuticalsonline

  16. Pingback: canadian pharmacy uk delivery

  17. Pingback: canadian drugs

  18. Pingback: pharmacy canada

  19. Pingback: global pharmacy canada

  20. Pingback: canadian pharmacy uk delivery

  21. Pingback: top rated online canadian pharmacies

  22. Pingback: pinshape.com/users/2441621-canadian-pharmaceutical-companies

  23. Pingback: buy viagra now

  24. Pingback: northwest pharmacies

  25. Pingback: https://pinshape.com/users/2445987-order-stromectol-over-the-counter

  26. Pingback: https://reallygoodemails.com/orderstromectoloverthecounter

  27. Pingback: https://challonge.com/en/orderstromectoloverthecounter

  28. Pingback: https://500px.com/p/orderstromectoloverthecounter

  29. Pingback: https://www.seje.gov.mz/question/order-stromectol-over-the-counter-6/

  30. Pingback: canadajobscenter.comauthorbuystromectol

  31. Pingback: online canadian pharmacy

  32. Pingback: https://aoc.stamford.edu/profile/canadianpharmaceuticalsonline/

  33. Pingback: northwest pharmacy canada

  34. Pingback: ktqt.ftu.edu.vnenquestion listcanadian-pharmaceuticals-for-usa-sales

  35. Pingback: discount canadian pharmacies

  36. Pingback: stromectol scabies treatment

  37. Pingback: ktqt.ftu.edu.vnenquestion listorder-stromectol-over-the-counter-10

  38. Pingback: orderstromectoloverthecounter.bandcamp.comreleases

  39. Pingback: www.provenexpert.comorder-stromectol-over-the-counter12

  40. Pingback: https://www.repairanswers.net/question/order-stromectol-over-the-counter-2/

  41. Pingback: https://www.repairanswers.net/question/stromectol-order-online/

  42. Pingback: canadajobscenter.comauthorarpreparof1989

  43. Pingback: aoc.stamford.eduprofilegoatunmantmen

  44. Pingback: web904.comstromectol-buy

  45. Pingback: https://web904.com/buy-ivermectin-online-fitndance/

  46. Pingback: https://glycvimepedd.bandcamp.com/releases

  47. Pingback: https://canadajobscenter.com/author/ereswasint/

  48. Pingback: https://aoc.stamford.edu/profile/hispennbackwin/

  49. Pingback: bursuppsligme.bandcamp.comreleases

  50. Pingback: https://pinshape.com/users/2461310-canadian-pharmacies-shipping-to-usa

  51. Pingback: https://pinshape.com/users/2462760-order-stromectol-over-the-counter

  52. Pingback: https://pinshape.com/users/2462910-order-stromectol-online

  53. Pingback: 500px.com/p/phraspilliti

  54. Pingback: https://web904.com/canadian-pharmaceuticals-for-usa-sales/

  55. Pingback: https://500px.com/p/skulogovid/?view=groups

  56. Pingback: 500px.compbersavahi?view=groups

  57. Pingback: reallygoodemails.comcanadianpharmaceuticalsonlineusa

  58. Pingback: www.provenexpert.comcanadian-pharmaceuticals-online-usa

  59. Pingback: canadian pharmacies online prescriptions

  60. Pingback: canadian medications

  61. Pingback: haikudeck.comcanadian-pharmaceuticals-online-personal-presentation-827506e003

  62. Pingback: buyersguide.americanbar.orgprofile4206420

  63. Pingback: https://experiment.com/users/canadianpharmacy

  64. Pingback: canada medication

  65. Pingback: stromectol generic

  66. Pingback: challonge.comgotsembpertvil

  67. Pingback: challonge.comcitlitigolf

  68. Pingback: order-stromectol-over-the-counter.estranky.czclankyorder-stromectol-over-the-counter.html

Leave a Comment