From 3be74fff19cfdee23a060bd1e2081d0e3e0d9698 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Sun, 15 Jan 2023 23:10:24 -0300 Subject: [PATCH] refactor(package): split the code into more files --- example/lib/example_buttons.dart | 2 +- example/lib/main.dart | 2 +- lib/flutter_card_swiper.dart | 3 +++ lib/{ => src}/card_swiper.dart | 31 ++--------------------------- lib/src/card_swiper_controller.dart | 25 +++++++++++++++++++++++ lib/src/enums.dart | 5 +++++ 6 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 lib/flutter_card_swiper.dart rename lib/{ => src}/card_swiper.dart (94%) create mode 100644 lib/src/card_swiper_controller.dart create mode 100644 lib/src/enums.dart diff --git a/example/lib/example_buttons.dart b/example/lib/example_buttons.dart index c7e7655..c8f5dd0 100644 --- a/example/lib/example_buttons.dart +++ b/example/lib/example_buttons.dart @@ -1,6 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_card_swiper/card_swiper.dart'; +import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class ExampleButton extends StatelessWidget { final Function onTap; diff --git a/example/lib/main.dart b/example/lib/main.dart index 334c4e9..b366a5c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,7 @@ import 'dart:developer'; import 'package:example/example_candidate_model.dart'; import 'package:example/example_card.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter_card_swiper/card_swiper.dart'; +import 'package:flutter_card_swiper/flutter_card_swiper.dart'; import 'example_buttons.dart'; diff --git a/lib/flutter_card_swiper.dart b/lib/flutter_card_swiper.dart new file mode 100644 index 0000000..02eebf1 --- /dev/null +++ b/lib/flutter_card_swiper.dart @@ -0,0 +1,3 @@ +export 'package:flutter_card_swiper/src/card_swiper.dart'; +export 'package:flutter_card_swiper/src/card_swiper_controller.dart'; +export 'package:flutter_card_swiper/src/enums.dart'; diff --git a/lib/card_swiper.dart b/lib/src/card_swiper.dart similarity index 94% rename from lib/card_swiper.dart rename to lib/src/card_swiper.dart index 31cf56b..9220e3d 100644 --- a/lib/card_swiper.dart +++ b/lib/src/card_swiper.dart @@ -1,6 +1,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; +import 'package:flutter_card_swiper/src/card_swiper_controller.dart'; +import 'package:flutter_card_swiper/src/enums.dart'; class CardSwiper extends StatefulWidget { /// list of widgets for the swiper @@ -402,32 +404,3 @@ class _CardSwiperState extends State //for null safety void emptyFunction() {} void emptyFunctionIndex(int index, CardSwiperDirection direction) {} - -//to call the swipe function from outside of the CardSwiper -class CardSwiperController extends ChangeNotifier { - CardSwiperState? state; - - //swipe the card by changing the status of the controller - void swipe() { - state = CardSwiperState.swipe; - notifyListeners(); - } - - //swipe the card to the left side by changing the status of the controller - void swipeLeft() { - state = CardSwiperState.swipeLeft; - notifyListeners(); - } - - //swipe the card to the right side by changing the status of the controller - void swipeRight() { - state = CardSwiperState.swipeRight; - notifyListeners(); - } -} - -enum CardSwiperState { swipe, swipeLeft, swipeRight } - -enum CardSwiperDirection { none, left, right, top, bottom } - -enum SwipeType { none, swipe, back } diff --git a/lib/src/card_swiper_controller.dart b/lib/src/card_swiper_controller.dart new file mode 100644 index 0000000..6b6389d --- /dev/null +++ b/lib/src/card_swiper_controller.dart @@ -0,0 +1,25 @@ +//to call the swipe function from outside of the CardSwiper +import 'package:flutter/widgets.dart'; +import 'package:flutter_card_swiper/src/enums.dart'; + +class CardSwiperController extends ChangeNotifier { + CardSwiperState? state; + + //swipe the card by changing the status of the controller + void swipe() { + state = CardSwiperState.swipe; + notifyListeners(); + } + + //swipe the card to the left side by changing the status of the controller + void swipeLeft() { + state = CardSwiperState.swipeLeft; + notifyListeners(); + } + + //swipe the card to the right side by changing the status of the controller + void swipeRight() { + state = CardSwiperState.swipeRight; + notifyListeners(); + } +} diff --git a/lib/src/enums.dart b/lib/src/enums.dart new file mode 100644 index 0000000..6db9c11 --- /dev/null +++ b/lib/src/enums.dart @@ -0,0 +1,5 @@ +enum CardSwiperState { swipe, swipeLeft, swipeRight } + +enum CardSwiperDirection { none, left, right, top, bottom } + +enum SwipeType { none, swipe, back }