From c1b0ca39e3310ee4fff00c79a70d323f32fc805c Mon Sep 17 00:00:00 2001 From: ricardodalarme Date: Tue, 9 Jan 2024 14:44:36 -0300 Subject: [PATCH] feat(AllowedSwipeDirection): make only and symmetric const constructors --- lib/src/allowed_swipe_direction.dart | 67 +++++++++++----------------- test/card_swipe_direction_test.dart | 12 ++--- test/card_swiper_test.dart | 16 +++---- 3 files changed, 39 insertions(+), 56 deletions(-) diff --git a/lib/src/allowed_swipe_direction.dart b/lib/src/allowed_swipe_direction.dart index 69486f3..7461b50 100644 --- a/lib/src/allowed_swipe_direction.dart +++ b/lib/src/allowed_swipe_direction.dart @@ -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; } diff --git a/test/card_swipe_direction_test.dart b/test/card_swipe_direction_test.dart index 3cb0902..2e6cddf 100644 --- a/test/card_swipe_direction_test.dart +++ b/test/card_swipe_direction_test.dart @@ -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); diff --git a/test/card_swiper_test.dart b/test/card_swiper_test.dart index dc6c002..bf89d3f 100644 --- a/test/card_swiper_test.dart +++ b/test/card_swiper_test.dart @@ -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, ), );