diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc7d8..1ddbe9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0 + +* add opacity as an option to the card transform + ## 0.0.1 * TODO: Describe initial release. diff --git a/example/lib/main.dart b/example/lib/main.dart index 8527dc8..fd5e993 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -60,16 +60,47 @@ class _CarouselExampleAppState extends State { onCardClick: _onClick, transforms: [ CardTransform( - x: 220, y: -85, angle: -math.pi / 12, scale: 0.3), + x: 220, + y: -85, + angle: -math.pi / 12, + scale: 0.3, + opacity: 0.2, + ), CardTransform( - x: 230, y: -80, angle: math.pi / 12, scale: 0.5), + x: 230, + y: -80, + angle: math.pi / 12, + scale: 0.5, + opacity: 0.4, + ), CardTransform( - x: 200, y: -75, angle: -math.pi / 12, scale: 0.6), + x: 200, + y: -75, + angle: -math.pi / 12, + scale: 0.6, + opacity: 0.6, + ), CardTransform( - x: 110, y: -60, angle: math.pi / 12, scale: 0.7), - CardTransform(x: 0, y: 0, angle: 0, scale: 1), + x: 110, + y: -60, + angle: math.pi / 12, + scale: 0.7, + opacity: 0.8, + ), CardTransform( - x: -270, y: 70, angle: -math.pi / 50, scale: 1), + x: 0, + y: 0, + angle: 0, + scale: 1, + opacity: 1.0, + ), + CardTransform( + x: -270, + y: 70, + angle: -math.pi / 50, + scale: 1, + opacity: 0.5, + ), ], builder: _buildCard, ), diff --git a/lib/src/models/card_transform.dart b/lib/src/models/card_transform.dart index 95ee728..7a5329b 100644 --- a/lib/src/models/card_transform.dart +++ b/lib/src/models/card_transform.dart @@ -5,11 +5,21 @@ class CardTransform { this.y = 0, this.angle = 0, this.scale = 1, - }); + this.opacity = 1.0, + }) : assert( + opacity >= 0, + 'Opacity cannot be negative', + ), + assert( + opacity <= 1.0, + 'Opacity needs to be between 0.0 and 1.0', + ); + double x; double y; double angle; double scale; + double opacity; /// [transitionPos] is a position value of a swipe for example. /// [other] is the position, scale, rotation @@ -20,6 +30,7 @@ class CardTransform { y: _transformValue(y, other.y, transitionPos), angle: _transformValue(angle, other.angle, transitionPos), scale: _transformValue(scale, other.scale, transitionPos), + opacity: _transformValue(opacity, other.opacity, transitionPos), ); } diff --git a/lib/src/widgets/carousel_card.dart b/lib/src/widgets/carousel_card.dart index 97285e4..1629b1e 100644 --- a/lib/src/widgets/carousel_card.dart +++ b/lib/src/widgets/carousel_card.dart @@ -20,7 +20,10 @@ class CarouselCard extends StatelessWidget { angle: cardTransform.angle, child: Transform.scale( scale: cardTransform.scale, - child: child, + child: Opacity( + opacity: cardTransform.opacity, + child: child, + ), ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 43bc60d..6def031 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,6 @@ name: carousel description: card carousel -version: 0.0.1 -homepage: +version: 0.1.0 environment: sdk: ">=2.17.6 <3.0.0"