chore: upgrade min sdk version to 3.0.0

This commit is contained in:
ricardodalarme 2024-01-28 13:32:18 -03:00
parent bea7ea77a5
commit 7b79e303f7
9 changed files with 53 additions and 80 deletions

View File

@ -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

View File

@ -6,8 +6,8 @@ class ExampleCard extends StatelessWidget {
const ExampleCard(
this.candidate, {
Key? key,
}) : super(key: key);
super.key,
});
@override
Widget build(BuildContext context) {

View File

@ -14,8 +14,8 @@ void main() {
class Example extends StatefulWidget {
const Example({
Key? key,
}) : super(key: key);
super.key,
});
@override
State<Example> createState() => _ExamplePageState();
@ -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),

View File

@ -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:

View File

@ -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) {
@ -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) {

View File

@ -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'),
};
}

View File

@ -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),
@ -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',
@ -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();

View File

@ -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) {
_detectedHorizontalDirection = direction;
widget.onSwipeDirectionChange
?.call(_detectedHorizontalDirection, _detectedVerticalDirection);
}
} else if (direction == CardSwiperDirection.top ||
direction == CardSwiperDirection.bottom) {
if (_detectedVerticalDirection != direction) {
switch (direction) {
case CardSwiperDirection.none:
_detectedVerticalDirection = direction;
_detectedHorizontalDirection = 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
@ -193,7 +187,6 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
switch (_swipeType) {
case SwipeType.swipe:
await _handleCompleteSwipe();
break;
default:
break;
}
@ -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) {

View File

@ -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: