refactor(package): split the code into more files

This commit is contained in:
Ricardo Dalarme 2023-01-15 23:10:24 -03:00
parent fd0ff6cfd6
commit 3be74fff19
6 changed files with 37 additions and 31 deletions

View File

@ -1,6 +1,6 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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 { class ExampleButton extends StatelessWidget {
final Function onTap; final Function onTap;

View File

@ -3,7 +3,7 @@ import 'dart:developer';
import 'package:example/example_candidate_model.dart'; import 'package:example/example_candidate_model.dart';
import 'package:example/example_card.dart'; import 'package:example/example_card.dart';
import 'package:flutter/cupertino.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'; import 'example_buttons.dart';

View File

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

View File

@ -1,6 +1,8 @@
import 'dart:math'; import 'dart:math';
import 'package:flutter/material.dart'; 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 { class CardSwiper extends StatefulWidget {
/// list of widgets for the swiper /// list of widgets for the swiper
@ -402,32 +404,3 @@ class _CardSwiperState extends State<CardSwiper>
//for null safety //for null safety
void emptyFunction() {} void emptyFunction() {}
void emptyFunctionIndex(int index, CardSwiperDirection direction) {} 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 }

View File

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

5
lib/src/enums.dart Normal file
View File

@ -0,0 +1,5 @@
enum CardSwiperState { swipe, swipeLeft, swipeRight }
enum CardSwiperDirection { none, left, right, top, bottom }
enum SwipeType { none, swipe, back }