feat(AllowedSwipeDirection): make only and symmetric const constructors

This commit is contained in:
ricardodalarme 2024-01-09 14:44:36 -03:00
parent 6df02e36ea
commit c1b0ca39e3
3 changed files with 39 additions and 56 deletions

View File

@ -1,25 +1,5 @@
/// Class to define the direction in which the card can be swiped
class AllowedSwipeDirection {
/// Set to true to allow the card to be swiped in the up direction
final bool up;
/// Set to true to allow the card to be swiped in the down direction
final bool down;
/// Set to true to allow the card to be swiped in the left direction
final bool left;
/// Set to true to allow the card to be swiped in the right direction
final bool right;
/// Define the direction in which the card can be swiped
const AllowedSwipeDirection._({
required this.up,
required this.down,
required this.left,
required this.right,
});
/// Allow the card to be swiped in any direction
const AllowedSwipeDirection.all()
: up = true,
@ -35,28 +15,31 @@ class AllowedSwipeDirection {
left = false;
/// Allow the card to be swiped in only the specified directions
factory AllowedSwipeDirection.only({
up = false,
down = false,
left = false,
right = false,
}) =>
AllowedSwipeDirection._(
up: up,
down: down,
left: left,
right: right,
);
const AllowedSwipeDirection.only({
this.up = false,
this.down = false,
this.left = false,
this.right = false,
});
/// Allow the card to be swiped symmetrically in horizontal or vertical directions
factory AllowedSwipeDirection.symmetric({
horizontal = false,
vertical = false,
}) =>
AllowedSwipeDirection._(
up: vertical,
down: vertical,
right: horizontal,
left: horizontal,
);
const AllowedSwipeDirection.symmetric({
bool horizontal = false,
bool vertical = false,
}) : up = vertical,
down = vertical,
left = horizontal,
right = horizontal;
/// Set to true to allow the card to be swiped in the up direction
final bool up;
/// Set to true to allow the card to be swiped in the down direction
final bool down;
/// Set to true to allow the card to be swiped in the left direction
final bool left;
/// Set to true to allow the card to be swiped in the right direction
final bool right;
}

View File

@ -21,7 +21,7 @@ void main() {
group('CardSwipeDirection.only() tests', () {
test('CardSwipeDirection.only(up:true) has only the up direction as true',
() {
final directions = AllowedSwipeDirection.only(up: true);
const directions = AllowedSwipeDirection.only(up: true);
expect(directions.up, true);
expect(directions.down, false);
expect(directions.right, false);
@ -31,7 +31,7 @@ void main() {
test(
'CardSwipeDirection.only(down:true) has only the set direction as true',
() {
final directions = AllowedSwipeDirection.only(down: true);
const directions = AllowedSwipeDirection.only(down: true);
expect(directions.up, false);
expect(directions.down, true);
expect(directions.right, false);
@ -41,7 +41,7 @@ void main() {
test(
'CardSwipeDirection.only(right:true) has only the set direction as true',
() {
final directions = AllowedSwipeDirection.only(right: true);
const directions = AllowedSwipeDirection.only(right: true);
expect(directions.up, false);
expect(directions.down, false);
expect(directions.right, true);
@ -51,7 +51,7 @@ void main() {
test(
'CardSwipeDirection.only(left:true) has only the set direction as true',
() {
final directions = AllowedSwipeDirection.only(left: true);
const directions = AllowedSwipeDirection.only(left: true);
expect(directions.up, false);
expect(directions.down, false);
expect(directions.right, false);
@ -63,7 +63,7 @@ void main() {
test(
'CardSwipeDirection.symmetric(horizontal:true) has left and right as true',
() {
final directions = AllowedSwipeDirection.symmetric(horizontal: true);
const directions = AllowedSwipeDirection.symmetric(horizontal: true);
expect(directions.up, false);
expect(directions.down, false);
expect(directions.right, true);
@ -72,7 +72,7 @@ void main() {
test('CardSwipeDirection.symmetric(vertical:true) has up and down as true',
() {
final directions = AllowedSwipeDirection.symmetric(vertical: true);
const directions = AllowedSwipeDirection.symmetric(vertical: true);
expect(directions.up, true);
expect(directions.down, true);
expect(directions.right, false);

View File

@ -477,7 +477,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(right: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(right: true),
cardBuilder: genericBuilder,
),
);
@ -498,7 +498,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(left: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(left: true),
cardBuilder: genericBuilder,
),
);
@ -519,7 +519,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(left: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(left: true),
cardBuilder: genericBuilder,
),
);
@ -540,7 +540,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(right: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(right: true),
cardBuilder: genericBuilder,
),
);
@ -561,7 +561,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(up: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(up: true),
cardBuilder: genericBuilder,
),
);
@ -582,7 +582,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(down: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(down: true),
cardBuilder: genericBuilder,
),
);
@ -603,7 +603,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(down: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(down: true),
cardBuilder: genericBuilder,
),
);
@ -624,7 +624,7 @@ void main() {
key: swiperKey,
cardsCount: 10,
numberOfCardsDisplayed: 1,
allowedSwipeDirection: AllowedSwipeDirection.only(up: true),
allowedSwipeDirection: const AllowedSwipeDirection.only(up: true),
cardBuilder: genericBuilder,
),
);