Ranish
Ranish

Reputation: 337

how to add Asset type image list into Carousel in flutter

I have list of Images in Asset type and I have already added items into it.

How can I show the Asset type image list in Carousel in flutter

List<Asset> images = List<Asset>();
    SizedBox(
                height: 150.0,
                width: 300.0,
                child: Carousel(
                  images: images,
                ),
                )

Upvotes: 0

Views: 2496

Answers (2)

Johny Saini
Johny Saini

Reputation: 909

 List<Asset> images = List<Asset>();
     SizedBox(
            height: 500.0,
            width: 300.0,
            child: CarouselSlider(
             items: images.map((image) => AssetThumb(
      asset: image,
      width: 300,
      height: 300,
    ),
)).toList(
),)

Upvotes: 1

Shri Hari L
Shri Hari L

Reputation: 4923

You can use this Flutter Package: https://pub.dev/packages/carousel_slider
Follow the instructions for Installation.


Import the Package import 'package:carousel_slider/carousel_slider.dart';


You can assign your List of Widgets (in your case Image.asset() or AssetImage)

CarouselSlider(
  options: CarouselOptions(height: 400.0),
  items: [ YOUR LIST HERE ],
)

Additional Options Reference: https://pub.dev/packages/carousel_slider/example

Upvotes: 0

Related Questions