Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/lib/example_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _ExampleRouteState extends State<ExampleRoute> {
else
// if the deck is complete, add a button to reset deck
Center(
child: FlatButton(
child: TextButton(
child: Text("Reset deck"),
onPressed: () => setState(() => currentCardIndex = 0),
),
Expand Down Expand Up @@ -86,11 +86,11 @@ class _ExampleRouteState extends State<ExampleRoute> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
TextButton(
child: Text("Left"),
onPressed: () => cardController.triggerSwipeLeft(),
),
FlatButton(
TextButton(
child: Text("Right"),
onPressed: () => cardController.triggerSwipeRight(),
),
Expand Down
6 changes: 3 additions & 3 deletions example/lib/example_slide_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _ExampleRouteSlideState extends State<ExampleRouteSlide> {
else
// if the deck is complete, add a button to reset deck
Center(
child: FlatButton(
child: TextButton(
child: Text("Reset deck"),
onPressed: () => setState(() => currentCardIndex = 0),
),
Expand Down Expand Up @@ -92,11 +92,11 @@ class _ExampleRouteSlideState extends State<ExampleRouteSlide> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
TextButton(
child: Text("Left"),
onPressed: () => cardController.triggerSwipeLeft(),
),
FlatButton(
TextButton(
child: Text("Right"),
onPressed: () => cardController.triggerSwipeRight(),
),
Expand Down
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'example_route.dart';
import 'example_slide_route.dart';

void main() => runApp(MyApp());
Expand Down
97 changes: 31 additions & 66 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
version: "1.2.0"
clock:
dependency: transitive
description:
name: collection
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.1.0"
collection:
dependency: transitive
description:
name: convert
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: crypto
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -67,48 +60,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -120,28 +92,28 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
swipeable_card:
dependency: "direct main"
description:
Expand All @@ -155,34 +127,27 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
version: "2.1.0"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.12.0-0.0 <3.0.0"
2 changes: 1 addition & 1 deletion lib/src/animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:swipeable_card/src/swipeable_widget_controller.dart';
Animation<Alignment> cardDismissAlignmentAnimation(
AnimationController controller,
Alignment startAlign,
Direction dir,
Direction? dir,
) {
double x, y;
// find direction it's being disissed
Expand Down
29 changes: 15 additions & 14 deletions lib/src/swipeable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import 'swipeable_widget_controller.dart';

class SwipeableWidget extends StatefulWidget {
SwipeableWidget({
Key key,
Key? key,
this.cardController,
this.animationDuration = 700,
this.horizontalThreshold = 0.85,
this.verticalThreshold = 0.95,
this.onLeftSwipe,
this.onRightSwipe,
this.scrollSensitivity = 6.0,
@required this.child,
required this.child,
this.nextCards,
}) : super(key: key);

final SwipeableWidgetController cardController;
final SwipeableWidgetController? cardController;

/// Animation duration in millseconds
final int animationDuration;
Expand All @@ -28,10 +28,10 @@ class SwipeableWidget extends StatefulWidget {
final double verticalThreshold;

/// Function executed when the card is swiped lieft
final Function onLeftSwipe;
final Function? onLeftSwipe;

/// Function executed when the card is swiped lieft
final Function onRightSwipe;
final Function? onRightSwipe;

/// The multiplier for the scroll value
final double scrollSensitivity;
Expand All @@ -41,20 +41,21 @@ class SwipeableWidget extends StatefulWidget {

/// Any widgets to show behind the [child]. These will most likely be the next
/// few cards in the deck
final List<Widget> nextCards;
final List<Widget>? nextCards;

@override
_SwipeableWidgetState createState() => _SwipeableWidgetState();
}

class _SwipeableWidgetState extends State<SwipeableWidget>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Alignment _childAlign;

late AnimationController _controller;
late Alignment _childAlign;
Alignment _initialAlignment = Alignment.center;

// stores the direction in which the card is being dismissed
Direction _dir;
Direction? _dir;

@override
void initState() {
Expand Down Expand Up @@ -87,7 +88,7 @@ class _SwipeableWidgetState extends State<SwipeableWidget>
child: Stack(
children: <Widget>[
// widgets behind current card
...widget.nextCards,
...?widget.nextCards,

// current card
child(),
Expand All @@ -114,7 +115,7 @@ class _SwipeableWidgetState extends State<SwipeableWidget>
animateCardLeaving(Direction.left);
else {
// when direction is null, it goes back to the center
animateCardLeaving(null);
animateCardLeaving();
}
}),
)
Expand All @@ -124,8 +125,8 @@ class _SwipeableWidgetState extends State<SwipeableWidget>
);
}

void animateCardLeaving(Direction dir) {
Function then;
void animateCardLeaving([Direction? dir]) {
Function? then;
switch (dir) {
case (Direction.left):
then = widget.onLeftSwipe;
Expand All @@ -145,7 +146,7 @@ class _SwipeableWidgetState extends State<SwipeableWidget>
_controller.value = 0.0;

// once the animation is over, execute the function
_controller.forward().then((value) => then());
_controller.forward().then((value) => then?.call());
}

Widget child() {
Expand Down
Loading