diff --git a/lib/carousel_options.dart b/lib/carousel_options.dart index ec29cd3..430af90 100644 --- a/lib/carousel_options.dart +++ b/lib/carousel_options.dart @@ -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, @@ -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. @@ -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, @@ -221,5 +226,6 @@ class CarouselOptions { clipBehavior: clipBehavior ?? this.clipBehavior, padEnds: padEnds ?? this.padEnds, overlayColor: overlayColor ?? this.overlayColor, + enlargeCenterFixedOthers: enlargeCenterFixedOthers ?? this.enlargeCenterFixedOthers, ); } diff --git a/lib/carousel_slider.dart b/lib/carousel_slider.dart index 9910c8b..4597a66 100644 --- a/lib/carousel_slider.dart +++ b/lib/carousel_slider.dart @@ -360,7 +360,8 @@ class CarouselSliderState extends State 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; }