Closed Welnnys closed 8 months ago
Hi @Welnnys, you can refer to the Horizontal
screen code (link attached below) to have to an idea how to use that. Also when you run the example app included in package, it will have three buttons on the home page, you can go to any one of them and search for InfiniteCarousel.builder
.
https://github.com/GeekyAnts/infinite-carousel-flutter/blob/main/example/lib/screens/horizontal.dart
Here's a example snippet for your reference:
final ScrollController _controller = InfiniteScrollController();
SizedBox(
height: 200,
child: InfiniteCarousel.builder(
// In this example, Items is the list of string containing image urls.
itemCount: items.length,
itemExtent: 200,
loop: true,
controller: _controller,
onIndexChanged: (index) {
print(index);
},
itemBuilder: (context, itemIndex, realIndex) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: GestureDetector(
onTap: () {
_controller.animateToItem(realIndex);
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
boxShadow: kElevationToShadow[2],
image: DecorationImage(
image: NetworkImage(items[itemIndex]),
fit: BoxFit.fill,
),
),
),
),
);
},
),
);
Please let me know if you need further help. Thanks.
this is what I get with this code
what I want is to have 3 different items in which I can put images in a horizontal way
@Welnnys, can you please send me more details?
flutter doctor -v
output.https://example.com/image1.jpg
, which is not a valid image, therefore I cannot debug why its not working.Please share a minimal working flutter application repository with me with the valid image urls you want to display. Thanks.
[√] Flutter (Channel stable, 3.19.0, on Microsoft Windows [Version 10.0.22631.3155], locale en-150) • Flutter version 3.19.0 on channel stable at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision bae5e49bc2 (3 weeks ago), 2024-02-13 17:46:18 -0800 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\Trade\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) • All Android licenses accepted.
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2023.1) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
[√] IntelliJ IDEA Ultimate Edition (version 2023.2) • IntelliJ at D:\IntelliJ\IntelliJ IDEA 2023.2.5 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart
[√] Connected device (2 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3155] • Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.66
[√] Network resources • All expected network resources are available.
! Doctor found issues in 2 categories.
Platform: Windows? not sure if u meant that
I don't have valid image url at the moment, I tried with some random ones but I would like to make it using images I have in a folder. The repository I am using is private so I can't share it with you sadly. I will link below what I want to make.
I ran the exact code that you shared with me https://pastebin.com/ccKN3Bvh
, but with valid image urls, and it worked. I have attached the screenshot with your code itself.
As I mentioned earlier, image url https://example.com/image1.jpg
present in the pastebin snippet is not a valid image so it can't work with any widget.
Please try with the image url i pasted below and share the error you are getting in terminal for me to debug more. As far as i can tell, issue is not with the package, but the wrong image urls (404) being passed to NetworkImage
the pastebin code snippet.
https://i.natgeofe.com/n/2a832501-483e-422f-985c-0e93757b7d84/6_4x3.jpg?w=1436&h=1078
hey, I just tried it out and it works now, thank you, any idea how I can show only the 2 items I have and nothing else, I don't want to have an infinite loop of the 2 items.
@Welnnys , great!
You can pass loop: false
in InfiniteCarousel.builder
for that.
You may want to experiment with different properties, like anchor
, center
, axis
and itemExtent
to correctly position your items as needed for your UI requirement.
Will do so, thank you for your time and patience. Have a good day/night :3
Awesome. Please feel free to ask any other queries. I will mark this issue as completed now.
I don't quite understand the example and how to make a carousel item, I would highly appreciate it if you guys comment an example which I can use. This is my code right now:
https://pastebin.com/6xMMF7Ha