Open nitinsun opened 4 years ago
I'm also facing the same issue. Did you find any solution?
maybe adding key:GlobalKey()
in CarouselSlider
will help, let me know if that helps
I'm having the same issue, tried GlobalKey
without success. It animates the slider but when it finishes and calls setState
on onPageChanged
it restarts to the first slide.
Custom Slider Code
CardSlider(
items: this._cards.map((card) => CardImageBox(card: card)).toList(),
onPageChanged: (index) => {
Timer(Duration(milliseconds: 500), (){
setState(() {
_currentCard = _cards[index];
});
})
}
)
Widget Code
class CardSlider extends StatefulWidget {
final List<Widget> items;
final Function(int index) onPageChanged;
CardSlider({
@required this.items,
this.onPageChanged
});
@override
_CardSliderState createState() => _CardSliderState();
}
class _CardSliderState extends State<CardSlider> {
int _current = 0;
GlobalKey key;
@override
Widget build(BuildContext context) {
return Column(
children: [
CarouselSlider(
key: key,
options: CarouselOptions(
disableCenter: false,
height: 175,
enableInfiniteScroll: false,
viewportFraction: 0.70,
onPageChanged: (index, reason) {
widget.onPageChanged(index);
},
),
items: widget.items,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.items.map(
(idx) {
int index = widget.items.indexOf(idx);
Color color = _current == index ? Theme.of(context).primaryColor : Color.fromRGBO(0, 0, 0, 0.3);
return SliderBullet(color: color);
},
).toList(),
),
],
);
}
}
@pedro-santiago did you ever find a fix for this? I am having the same problem.
i want custom carousel slider that update when every item add to array that assigned to array.