Skip to content

Commit

Permalink
chore: upgrade min sdk version to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardodalarme committed Jan 28, 2024
1 parent bea7ea7 commit 7b79e30
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 79 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

## [7.0.0]

- **BREAKING CHANGE**:
- Upgrade min dart sdk to 3.0.0

## [6.1.0]

- Fixes cannot access context in onSwipe when no cards left then "destroy" the widget tree
Expand Down
4 changes: 2 additions & 2 deletions example/lib/example_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ExampleCard extends StatelessWidget {

const ExampleCard(
this.candidate, {
Key? key,
}) : super(key: key);
super.key,
});

@override
Widget build(BuildContext context) {
Expand Down
8 changes: 2 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void main() {

class Example extends StatefulWidget {
const Example({
Key? key,
}) : super(key: key);
super.key,
});

@override
State<Example> createState() => _ExamplePageState();
Expand Down Expand Up @@ -65,10 +65,6 @@ class _ExamplePageState extends State<Example> {
onPressed: controller.undo,
child: const Icon(Icons.rotate_left),
),
FloatingActionButton(
onPressed: controller.swipe,
child: const Icon(Icons.rotate_right),
),
FloatingActionButton(
onPressed: controller.swipeLeft,
child: const Icon(Icons.keyboard_arrow_left),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish_to: "none"
version: 0.0.1

environment:
sdk: ">=2.15.0 <4.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
flutter:
Expand Down
38 changes: 14 additions & 24 deletions lib/src/card_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,13 @@ class CardAnimation {
}

void animate(BuildContext context, CardSwiperDirection direction) {
switch (direction) {
case CardSwiperDirection.left:
return animateHorizontally(context, false);
case CardSwiperDirection.right:
return animateHorizontally(context, true);
case CardSwiperDirection.top:
return animateVertically(context, false);
case CardSwiperDirection.bottom:
return animateVertically(context, true);
default:
return;
}
return switch (direction) {
CardSwiperDirection.left => animateHorizontally(context, false),
CardSwiperDirection.right => animateHorizontally(context, true),
CardSwiperDirection.top => animateVertically(context, false),
CardSwiperDirection.bottom => animateVertically(context, true),
CardSwiperDirection.none => null,
};
}

void animateHorizontally(BuildContext context, bool isToRight) {
Expand Down Expand Up @@ -215,18 +210,13 @@ class CardAnimation {
}

void animateUndo(BuildContext context, CardSwiperDirection direction) {
switch (direction) {
case CardSwiperDirection.left:
return animateUndoHorizontally(context, false);
case CardSwiperDirection.right:
return animateUndoHorizontally(context, true);
case CardSwiperDirection.top:
return animateUndoVertically(context, false);
case CardSwiperDirection.bottom:
return animateUndoVertically(context, true);
default:
return;
}
return switch (direction) {
CardSwiperDirection.left => animateUndoHorizontally(context, false),
CardSwiperDirection.right => animateUndoHorizontally(context, true),
CardSwiperDirection.top => animateUndoVertically(context, false),
CardSwiperDirection.bottom => animateUndoVertically(context, true),
_ => null
};
}

void animateUndoHorizontally(BuildContext context, bool isToRight) {
Expand Down
19 changes: 7 additions & 12 deletions lib/src/utils/direction_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_card_swiper/src/enums.dart';

extension DirectionExtension on CardSwiperDirection {
Axis get axis {
switch (this) {
case CardSwiperDirection.left:
case CardSwiperDirection.right:
return Axis.horizontal;
case CardSwiperDirection.top:
case CardSwiperDirection.bottom:
return Axis.vertical;
case CardSwiperDirection.none:
throw Exception('Direction is none');
}
}
Axis get axis => switch (this) {
CardSwiperDirection.left ||
CardSwiperDirection.right =>
Axis.horizontal,
CardSwiperDirection.top || CardSwiperDirection.bottom => Axis.vertical,
CardSwiperDirection.none => throw Exception('Direction is none'),
};
}
5 changes: 2 additions & 3 deletions lib/src/widget/card_swiper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class CardSwiper extends StatefulWidget {
const CardSwiper({
required this.cardBuilder,
required this.cardsCount,
Key? key,
this.controller,
this.initialIndex = 0,
this.padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 25),
Expand All @@ -150,6 +149,7 @@ class CardSwiper extends StatefulWidget {
this.numberOfCardsDisplayed = 2,
this.onUndo,
this.backCardOffset = const Offset(0, 40),
super.key,
}) : assert(
maxAngle >= 0 && maxAngle <= 360,
'maxAngle must be between 0 and 360',
Expand All @@ -173,8 +173,7 @@ class CardSwiper extends StatefulWidget {
assert(
initialIndex >= 0 && initialIndex < cardsCount,
'initialIndex must be between 0 and [cardsCount]',
),
super(key: key);
);

@override
State createState() => _CardSwiperState();
Expand Down
48 changes: 18 additions & 30 deletions lib/src/widget/card_swiper_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,20 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
}

void onSwipeDirectionChanged(CardSwiperDirection direction) {
if (direction == CardSwiperDirection.none) {
_detectedVerticalDirection = direction;
_detectedHorizontalDirection = direction;
widget.onSwipeDirectionChange
?.call(_detectedHorizontalDirection, _detectedVerticalDirection);
} else if (direction == CardSwiperDirection.right ||
direction == CardSwiperDirection.left) {
if (_detectedHorizontalDirection != direction) {
switch (direction) {
case CardSwiperDirection.none:
_detectedVerticalDirection = direction;
_detectedHorizontalDirection = direction;
widget.onSwipeDirectionChange
?.call(_detectedHorizontalDirection, _detectedVerticalDirection);
}
} else if (direction == CardSwiperDirection.top ||
direction == CardSwiperDirection.bottom) {
if (_detectedVerticalDirection != direction) {
case CardSwiperDirection.right:
case CardSwiperDirection.left:
_detectedHorizontalDirection = direction;
case CardSwiperDirection.top:
case CardSwiperDirection.bottom:
_detectedVerticalDirection = direction;
widget.onSwipeDirectionChange
?.call(_detectedHorizontalDirection, _detectedVerticalDirection);
}
}

widget.onSwipeDirectionChange
?.call(_detectedHorizontalDirection, _detectedVerticalDirection);
}

@override
Expand Down Expand Up @@ -193,7 +187,6 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
switch (_swipeType) {
case SwipeType.swipe:
await _handleCompleteSwipe();
break;
default:
break;
}
Expand Down Expand Up @@ -256,18 +249,13 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
}

bool _isValidDirection(CardSwiperDirection direction) {
switch (direction) {
case CardSwiperDirection.left:
return widget.allowedSwipeDirection.left;
case CardSwiperDirection.right:
return widget.allowedSwipeDirection.right;
case CardSwiperDirection.top:
return widget.allowedSwipeDirection.up;
case CardSwiperDirection.bottom:
return widget.allowedSwipeDirection.down;
default:
return false;
}
return switch (direction) {
CardSwiperDirection.left => widget.allowedSwipeDirection.left,
CardSwiperDirection.right => widget.allowedSwipeDirection.right,
CardSwiperDirection.top => widget.allowedSwipeDirection.up,
CardSwiperDirection.bottom => widget.allowedSwipeDirection.down,
_ => false
};
}

void _swipe(CardSwiperDirection direction) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues
version: 6.1.0

environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=3.0.0 <4.0.0"
flutter: ">=1.17.0"

dependencies:
Expand Down

0 comments on commit 7b79e30

Please sign in to comment.