diff --git a/example/lib/example_route.dart b/example/lib/example_route.dart index 709dbb1..830be98 100644 --- a/example/lib/example_route.dart +++ b/example/lib/example_route.dart @@ -50,7 +50,7 @@ class _ExampleRouteState extends State { 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), ), @@ -86,11 +86,11 @@ class _ExampleRouteState extends State { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - FlatButton( + TextButton( child: Text("Left"), onPressed: () => cardController.triggerSwipeLeft(), ), - FlatButton( + TextButton( child: Text("Right"), onPressed: () => cardController.triggerSwipeRight(), ), diff --git a/example/lib/example_slide_route.dart b/example/lib/example_slide_route.dart index 60a7e94..fdfab3f 100644 --- a/example/lib/example_slide_route.dart +++ b/example/lib/example_slide_route.dart @@ -50,7 +50,7 @@ class _ExampleRouteSlideState extends State { 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), ), @@ -92,11 +92,11 @@ class _ExampleRouteSlideState extends State { return Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - FlatButton( + TextButton( child: Text("Left"), onPressed: () => cardController.triggerSwipeLeft(), ), - FlatButton( + TextButton( child: Text("Right"), onPressed: () => cardController.triggerSwipeRight(), ), diff --git a/example/lib/main.dart b/example/lib/main.dart index c3fec59..c9fc52f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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()); diff --git a/example/pubspec.lock b/example/pubspec.lock index 8210349..cf5abfb 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 @@ -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 @@ -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: @@ -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" diff --git a/lib/src/animations.dart b/lib/src/animations.dart index 5582805..cf9cebb 100644 --- a/lib/src/animations.dart +++ b/lib/src/animations.dart @@ -4,7 +4,7 @@ import 'package:swipeable_card/src/swipeable_widget_controller.dart'; Animation cardDismissAlignmentAnimation( AnimationController controller, Alignment startAlign, - Direction dir, + Direction? dir, ) { double x, y; // find direction it's being disissed diff --git a/lib/src/swipeable.dart b/lib/src/swipeable.dart index 1dcbec0..0c38cdd 100644 --- a/lib/src/swipeable.dart +++ b/lib/src/swipeable.dart @@ -4,7 +4,7 @@ import 'swipeable_widget_controller.dart'; class SwipeableWidget extends StatefulWidget { SwipeableWidget({ - Key key, + Key? key, this.cardController, this.animationDuration = 700, this.horizontalThreshold = 0.85, @@ -12,11 +12,11 @@ class SwipeableWidget extends StatefulWidget { 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; @@ -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; @@ -41,7 +41,7 @@ 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 nextCards; + final List? nextCards; @override _SwipeableWidgetState createState() => _SwipeableWidgetState(); @@ -49,12 +49,13 @@ class SwipeableWidget extends StatefulWidget { class _SwipeableWidgetState extends State 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() { @@ -87,7 +88,7 @@ class _SwipeableWidgetState extends State child: Stack( children: [ // widgets behind current card - ...widget.nextCards, + ...?widget.nextCards, // current card child(), @@ -114,7 +115,7 @@ class _SwipeableWidgetState extends State animateCardLeaving(Direction.left); else { // when direction is null, it goes back to the center - animateCardLeaving(null); + animateCardLeaving(); } }), ) @@ -124,8 +125,8 @@ class _SwipeableWidgetState extends State ); } - void animateCardLeaving(Direction dir) { - Function then; + void animateCardLeaving([Direction? dir]) { + Function? then; switch (dir) { case (Direction.left): then = widget.onLeftSwipe; @@ -145,7 +146,7 @@ class _SwipeableWidgetState extends State _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() { diff --git a/lib/src/swipeable_slide.dart b/lib/src/swipeable_slide.dart index 1f9611e..2ca55e6 100644 --- a/lib/src/swipeable_slide.dart +++ b/lib/src/swipeable_slide.dart @@ -2,23 +2,23 @@ import 'package:flutter/material.dart'; class SwipeableWidgetSlide extends StatelessWidget { const SwipeableWidgetSlide({ - Key key, + required Key key, this.onLeftSwipe, this.onRightSwipe, this.onTopSwipe, this.onBottomSwipe, - @required this.child, + required this.child, this.nextCards = const [], }) : super(key: key); - final Function onLeftSwipe; - final Function onRightSwipe; - final Function onTopSwipe; - final Function onBottomSwipe; + final Function? onLeftSwipe; + final Function? onRightSwipe; + final Function? onTopSwipe; + final Function? onBottomSwipe; /// Required, this is the actual card that can be swiped final Widget child; - final List nextCards; + final List nextCards; @override Widget build(BuildContext context) { @@ -39,21 +39,21 @@ class SwipeableWidgetSlide extends StatelessWidget { // Using a dismissible instead of animations may give better performance // especially on lower end devices child: Dismissible( - key: key, + key: key!, direction: DismissDirection.vertical, onDismissed: (DismissDirection dir) { - if (dir == DismissDirection.up) onTopSwipe(); - if (dir == DismissDirection.down) onBottomSwipe(); + if (dir == DismissDirection.up) onTopSwipe?.call(); + if (dir == DismissDirection.down) onBottomSwipe?.call(); }, // nesting another dismissible so we can get vertical and horizontal // dismiss directions child: Dismissible( - key: key, + key: key!, direction: DismissDirection.horizontal, onDismissed: (DismissDirection dir) { - if (dir == DismissDirection.startToEnd) onRightSwipe(); - if (dir == DismissDirection.endToStart) onLeftSwipe(); + if (dir == DismissDirection.startToEnd) onRightSwipe?.call(); + if (dir == DismissDirection.endToStart) onLeftSwipe?.call(); }, child: Container( // By default, the dismissble will disapear when it is beyond it's diff --git a/lib/src/swipeable_widget_controller.dart b/lib/src/swipeable_widget_controller.dart index 98c78db..19e3e75 100644 --- a/lib/src/swipeable_widget_controller.dart +++ b/lib/src/swipeable_widget_controller.dart @@ -1,7 +1,7 @@ typedef TriggerListener = void Function(Direction dir); class SwipeableWidgetController { - TriggerListener _listener; + late TriggerListener _listener; void triggerSwipeLeft() => _listener(Direction.left); diff --git a/pubspec.lock b/pubspec.lock index 97283e8..24196be 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 @@ -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 @@ -120,62 +92,55 @@ 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" term_glyph: dependency: transitive description: 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.2 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 444482f..0382dee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: swipeable_card description: Add swipeable card-like widgets for games or interactive onboarding screens -version: 1.0.2 +version: 1.0.3 homepage: https://github.com/ninest/swipeable_card environment: - sdk: ">=2.6.0 <3.0.0" + sdk: ">=2.12.2 <3.0.0" dependencies: flutter: