-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update controller to use stream
- Loading branch information
1 parent
7b79e30
commit a79449d
Showing
11 changed files
with
165 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_card_swiper/src/controller/controller_event.dart'; | ||
import 'package:flutter_card_swiper/src/enums.dart'; | ||
|
||
/// A controller that can be used to trigger swipes on a CardSwiper widget. | ||
class CardSwiperController { | ||
final _eventController = StreamController<ControllerEvent>.broadcast(); | ||
|
||
/// Stream of events that can be used to swipe the card. | ||
Stream<ControllerEvent> get events => _eventController.stream; | ||
|
||
/// Swipe the card to a specific direction. | ||
void swipe(CardSwiperDirection direction) { | ||
_eventController.add(ControllerSwipeEvent(direction)); | ||
} | ||
|
||
// Undo the last swipe | ||
void undo() { | ||
_eventController.add(const ControllerUndoEvent()); | ||
} | ||
|
||
Future<void> dispose() async { | ||
await _eventController.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:flutter_card_swiper/flutter_card_swiper.dart'; | ||
|
||
abstract class ControllerEvent { | ||
const ControllerEvent(); | ||
} | ||
|
||
class ControllerSwipeEvent extends ControllerEvent { | ||
final CardSwiperDirection direction; | ||
|
||
const ControllerSwipeEvent(this.direction); | ||
} | ||
|
||
class ControllerUndoEvent extends ControllerEvent { | ||
const ControllerUndoEvent(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
enum CardSwiperState { | ||
swipe, | ||
swipeLeft, | ||
swipeRight, | ||
swipeTop, | ||
swipeBottom, | ||
undo | ||
} | ||
|
||
enum CardSwiperDirection { none, left, right, top, bottom } | ||
|
||
enum SwipeType { none, swipe, back, undo } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.