serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.56k stars 530 forks source link

The itemBuilder Runs when itemCount is zero #266

Open omidraha opened 3 years ago

omidraha commented 3 years ago

The itemBuilder Runs when itemCount is zero

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: SafeArea(
        child: Scaffold(
          body: CarouselSlider.builder(
            itemCount: 0,
            itemBuilder:
                (BuildContext context, int sliderIndex, int realIndex) {
              return Center(
                child: Container(
                  child: Text('Why ??'),
                ),
              );
            },
            options: CarouselOptions(),
          ),
        ),
      ),
    );
  }
}
prateekmedia commented 3 years ago

It is due to the code found in this file https://github.com/serenader2014/flutter_carousel_slider/blob/master/lib/carousel_slider.dart is what I think.

I don't know you could try setting the value to -1, maybe it could solve, I am not sure.