Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion lib/carousel_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class CarouselOptions {

final Color? 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,
Expand Down Expand Up @@ -163,6 +166,7 @@ class CarouselOptions {
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 +197,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 +226,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