Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions lib/carousel_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,38 @@ class CarouselOptions {

final Color? overlayColor;

CarouselOptions({
this.height,
this.aspectRatio = 16 / 9,
this.viewportFraction = 0.8,
this.initialPage = 0,
this.enableInfiniteScroll = true,
this.animateToClosest = true,
this.reverse = false,
this.autoPlay = false,
this.autoPlayInterval = const Duration(seconds: 4),
this.autoPlayAnimationDuration = const Duration(milliseconds: 800),
this.autoPlayCurve = Curves.fastOutSlowIn,
this.enlargeCenterPage = false,
this.onPageChanged,
this.onScrolled,
this.scrollPhysics,
this.pageSnapping = true,
this.scrollDirection = Axis.horizontal,
this.pauseAutoPlayOnTouch = true,
this.pauseAutoPlayOnManualNavigate = true,
this.pauseAutoPlayInFiniteScroll = false,
this.pageViewKey,
this.enlargeStrategy = CenterPageEnlargeStrategy.scale,
this.enlargeFactor = 0.3,
this.disableCenter = false,
this.padEnds = true,
this.clipBehavior = Clip.hardEdge,
this.overlayColor,
});
//This property defaults to false, if set to true, the center page will be enlarged and the other pages will be fixed.
final bool enlargeCenterFixedOthers;

CarouselOptions(
{this.height,
this.aspectRatio = 16 / 9,
this.viewportFraction = 0.8,
this.initialPage = 0,
this.enableInfiniteScroll = true,
this.animateToClosest = true,
this.reverse = false,
this.autoPlay = false,
this.autoPlayInterval = const Duration(seconds: 4),
this.autoPlayAnimationDuration = const Duration(milliseconds: 800),
this.autoPlayCurve = Curves.fastOutSlowIn,
this.enlargeCenterPage = false,
this.onPageChanged,
this.onScrolled,
this.scrollPhysics,
this.pageSnapping = true,
this.scrollDirection = Axis.horizontal,
this.pauseAutoPlayOnTouch = true,
this.pauseAutoPlayOnManualNavigate = true,
this.pauseAutoPlayInFiniteScroll = false,
this.pageViewKey,
this.enlargeStrategy = CenterPageEnlargeStrategy.scale,
this.enlargeFactor = 0.3,
this.disableCenter = false,
this.padEnds = true,
this.clipBehavior = Clip.hardEdge,
this.overlayColor,
this.enlargeCenterFixedOthers = false});

///Generate new [CarouselOptions] based on old ones.

Expand Down Expand Up @@ -193,7 +196,8 @@ class CarouselOptions {
bool? disableCenter,
Clip? clipBehavior,
bool? padEnds,
Color? overlayColor}) =>
Color? overlayColor,
bool? enlargeCenterFixedOthers}) =>
CarouselOptions(
height: height ?? this.height,
aspectRatio: aspectRatio ?? this.aspectRatio,
Expand Down Expand Up @@ -221,5 +225,6 @@ class CarouselOptions {
clipBehavior: clipBehavior ?? this.clipBehavior,
padEnds: padEnds ?? this.padEnds,
overlayColor: overlayColor ?? this.overlayColor,
enlargeCenterFixedOthers: enlargeCenterFixedOthers ?? this.enlargeCenterFixedOthers,
);
}
3 changes: 2 additions & 1 deletion lib/carousel_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ class CarouselSliderState extends State<CarouselSlider> with TickerProviderState
}

final double enlargeFactor = options.enlargeFactor.clamp(0.0, 1.0);
final num distortionRatio = (1 - (itemOffset.abs() * enlargeFactor)).clamp(0.0, 1.0);
final offsetValue = options.enlargeCenterFixedOthers ? itemOffset.abs().clamp(0, 1) : itemOffset.abs();
final num distortionRatio = (1 - (offsetValue * enlargeFactor)).clamp(0.0, 1.0);
distortionValue = Curves.easeOut.transform(distortionRatio as double);
opacityValue = 1 - distortionRatio;
}
Expand Down