feat(AllowedSwipeDirection): make only and symmetric const constructors
This commit is contained in:
parent
6df02e36ea
commit
c1b0ca39e3
|
|
@ -1,25 +1,5 @@
|
||||||
/// Class to define the direction in which the card can be swiped
|
/// Class to define the direction in which the card can be swiped
|
||||||
class AllowedSwipeDirection {
|
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
|
/// Allow the card to be swiped in any direction
|
||||||
const AllowedSwipeDirection.all()
|
const AllowedSwipeDirection.all()
|
||||||
: up = true,
|
: up = true,
|
||||||
|
|
@ -35,28 +15,31 @@ class AllowedSwipeDirection {
|
||||||
left = false;
|
left = false;
|
||||||
|
|
||||||
/// Allow the card to be swiped in only the specified directions
|
/// Allow the card to be swiped in only the specified directions
|
||||||
factory AllowedSwipeDirection.only({
|
const AllowedSwipeDirection.only({
|
||||||
up = false,
|
this.up = false,
|
||||||
down = false,
|
this.down = false,
|
||||||
left = false,
|
this.left = false,
|
||||||
right = false,
|
this.right = false,
|
||||||
}) =>
|
});
|
||||||
AllowedSwipeDirection._(
|
|
||||||
up: up,
|
|
||||||
down: down,
|
|
||||||
left: left,
|
|
||||||
right: right,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Allow the card to be swiped symmetrically in horizontal or vertical directions
|
/// Allow the card to be swiped symmetrically in horizontal or vertical directions
|
||||||
factory AllowedSwipeDirection.symmetric({
|
const AllowedSwipeDirection.symmetric({
|
||||||
horizontal = false,
|
bool horizontal = false,
|
||||||
vertical = false,
|
bool vertical = false,
|
||||||
}) =>
|
}) : up = vertical,
|
||||||
AllowedSwipeDirection._(
|
down = vertical,
|
||||||
up: vertical,
|
left = horizontal,
|
||||||
down: vertical,
|
right = horizontal;
|
||||||
right: horizontal,
|
|
||||||
left: 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ void main() {
|
||||||
group('CardSwipeDirection.only() tests', () {
|
group('CardSwipeDirection.only() tests', () {
|
||||||
test('CardSwipeDirection.only(up:true) has only the up direction as true',
|
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.up, true);
|
||||||
expect(directions.down, false);
|
expect(directions.down, false);
|
||||||
expect(directions.right, false);
|
expect(directions.right, false);
|
||||||
|
|
@ -31,7 +31,7 @@ void main() {
|
||||||
test(
|
test(
|
||||||
'CardSwipeDirection.only(down:true) has only the set direction as true',
|
'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.up, false);
|
||||||
expect(directions.down, true);
|
expect(directions.down, true);
|
||||||
expect(directions.right, false);
|
expect(directions.right, false);
|
||||||
|
|
@ -41,7 +41,7 @@ void main() {
|
||||||
test(
|
test(
|
||||||
'CardSwipeDirection.only(right:true) has only the set direction as true',
|
'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.up, false);
|
||||||
expect(directions.down, false);
|
expect(directions.down, false);
|
||||||
expect(directions.right, true);
|
expect(directions.right, true);
|
||||||
|
|
@ -51,7 +51,7 @@ void main() {
|
||||||
test(
|
test(
|
||||||
'CardSwipeDirection.only(left:true) has only the set direction as true',
|
'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.up, false);
|
||||||
expect(directions.down, false);
|
expect(directions.down, false);
|
||||||
expect(directions.right, false);
|
expect(directions.right, false);
|
||||||
|
|
@ -63,7 +63,7 @@ void main() {
|
||||||
test(
|
test(
|
||||||
'CardSwipeDirection.symmetric(horizontal:true) has left and right as true',
|
'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.up, false);
|
||||||
expect(directions.down, false);
|
expect(directions.down, false);
|
||||||
expect(directions.right, true);
|
expect(directions.right, true);
|
||||||
|
|
@ -72,7 +72,7 @@ void main() {
|
||||||
|
|
||||||
test('CardSwipeDirection.symmetric(vertical:true) has up and down as true',
|
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.up, true);
|
||||||
expect(directions.down, true);
|
expect(directions.down, true);
|
||||||
expect(directions.right, false);
|
expect(directions.right, false);
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(right: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(right: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -498,7 +498,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(left: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(left: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -519,7 +519,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(left: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(left: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -540,7 +540,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(right: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(right: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -561,7 +561,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(up: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(up: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -582,7 +582,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(down: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(down: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -603,7 +603,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(down: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(down: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
@ -624,7 +624,7 @@ void main() {
|
||||||
key: swiperKey,
|
key: swiperKey,
|
||||||
cardsCount: 10,
|
cardsCount: 10,
|
||||||
numberOfCardsDisplayed: 1,
|
numberOfCardsDisplayed: 1,
|
||||||
allowedSwipeDirection: AllowedSwipeDirection.only(up: true),
|
allowedSwipeDirection: const AllowedSwipeDirection.only(up: true),
|
||||||
cardBuilder: genericBuilder,
|
cardBuilder: genericBuilder,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue