Skip to content

Commit

Permalink
added a itemExtent variable
Browse files Browse the repository at this point in the history
To create the scaling effect, it's necessary to use the itemExtent value to perform calculations. It's easier to understand it using a variable to store the itemExtent value.
  • Loading branch information
al4nnw authored Mar 27, 2022
1 parent 42cf721 commit e68a494
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions example/lib/screens/complex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class _ComplexState extends State<Complex> {
double _anchor = 0.0;
bool _center = true;
double _velocityFactor = 0.2;
final double _itemExtent = 120;
late InfiniteScrollController _controller;

@override
Expand All @@ -39,7 +40,7 @@ class _ComplexState extends State<Complex> {
height: 200,
child: InfiniteCarousel.builder(
itemCount: kDemoImages.length,
itemExtent: 120,
itemExtent: _itemExtent,
center: _center,
anchor: _anchor,
velocityFactor: _velocityFactor,
Expand All @@ -54,13 +55,13 @@ class _ComplexState extends State<Complex> {
: null,
controller: _controller,
itemBuilder: (context, itemIndex, realIndex) {
final currentOffset = 120 * realIndex;
final currentOffset = _itemExtent * realIndex;
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
final diff = (_controller.offset - currentOffset);
final maxPadding = 10.0;
final _carouselRatio = 120 / maxPadding;
final _carouselRatio = _itemExtent / maxPadding;

return Padding(
padding: EdgeInsets.only(
Expand Down

0 comments on commit e68a494

Please sign in to comment.