0

I'm new to flutter and I'm very adventurous when it comes to discovering its hidden potential. I've tried a number of ways to implement what I want and I can't find the most effective way.

First, for example, I have a List<String> imagePath = ["assets/img1.jpg","assets/img2.jpg","assets/img3.jpg","assets/img4.jpg"];

I know that the Carousel Widget uses "image" parameter which accepts a list of "Image Widgets".

I know the easiest way to show this List<String> imagePath is to just simply use Listview.builder. But I want to utilize the feature of the Carousel wherein you can modify the transition animation and the most important part is the dot indicator.

SO if you guys have any ideas on how can I put my List inside the Carousel widget, That would be a great help!

I would appreciate any solutions!

nerdy kid
  • 371
  • 1
  • 3
  • 14

1 Answers1

1

If your Carousel receives a list of image widgets you can use the Image.asset constructor with the paths in your list. https://api.flutter.dev/flutter/widgets/Image/Image.asset.html

Martyns
  • 3,605
  • 22
  • 33
  • Yes. That would be the solution if I only have few list. what if I have thousands? can I use a loop inside? wouldn't that affect the performance of the app? – nerdy kid Sep 09 '19 at 12:31
  • Where is your Carousel widget from? For it to be performant it should provide some kind of builder method. But if that is not the case, you can file an issue to the package repository. – Martyns Sep 09 '19 at 12:34
  • It's inside a Listview.builder – nerdy kid Sep 09 '19 at 12:38
  • I don't recall any Carousel widget in the Flutter SDK. Correct me if I am wrong. Unless you require some specific features from that Carousel widget, you can achieve a performant "carousel" with a horizontal ListView.builder with Image.asset s inside. – Martyns Sep 09 '19 at 12:41
  • it's actually a flutter package. sorry if I didn't include it. Here's the link -> https://pub.dev/packages/carousel_pro – nerdy kid Sep 09 '19 at 12:46
  • I think you could ask the author of the package. But, are you sure you need a Carousel to display 1000 images? – Martyns Sep 09 '19 at 12:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/199182/discussion-between-martyns-and-nerdy-kid). – Martyns Sep 09 '19 at 12:56